Skip to content

Commit 2266811

Browse files
authored
Merge pull request #27 from vegarringdal/new_loader
Removed hmr/reload and better errors
2 parents 8f6bfaa + 6217e05 commit 2266811

17 files changed

+5458
-284
lines changed

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
# fuse-box-aurelia-loader
22

3-
###How to install
3+
### How to install
44
```npm install git://github.com/fuse-box/fuse-box-aurelia-loader```
55

6-
###Sample
6+
7+
### How to use
8+
79
```javascript
810

911
// optional..
1012
// activate logging (when aurelia developmentLogging is used)
11-
(<any>window).FUSEBOX_AURELIA_LOADER_LOGGING = true;
13+
// have this as optional, since it prints out a lot.
14+
window.FUSEBOX_AURELIA_LOADER_LOGGING = true;
1215

13-
// activate hot reload, need aurelia-hot-module-reload to work, and "useCache" needs to be set to true
14-
(<any>window).FUSEBOX_AURELIA_LOADER_HMR = true;
1516

16-
// just reload document on fusebox hrm event (file change)
17-
(<any>window).FUSEBOX_AURELIA_LOADER_RELOAD = true;
18-
19-
//These can also be set by using the "EnvPlugin" in fuse.
20-
//fb.EnvPlugin({
17+
//These can also be set by using the "EnvPlugin" in fuse build setup
18+
// EnvPlugin({
2119
// FB_AU_LOG: false,
22-
// FB_AU_HMR: false,
23-
// FB_AU_RELOAD: true
2420
//})
2521

26-
// if you are having issues check console for FuseBox.import("process").env to make sure it set
27-
28-
22+
// TIP: If you are having issues check console for FuseBox.import("process").env to make sure it set
2923

3024

25+
// The next 2 import statements can be replaced by plugin in your fuse build setup
26+
// See "autoLoadAureliaLoaders" in next code block
3127
// add custom loader for fuse
3228
import 'fuse-box-aurelia-loader';
33-
3429
// start aurelia bootstrapper
3530
import 'aurelia-bootstrapper';
3631

32+
3733
// aurelia configuration
3834
export function configure(aurelia) {
3935
aurelia.use
@@ -45,3 +41,23 @@ export function configure(aurelia) {
4541
```
4642

4743

44+
### Plugin sample
45+
Simple auto load plugin to inject the loaders
46+
47+
```javascript
48+
var autoLoadAureliaLoaders =function() {
49+
var loader = function(){}
50+
loader.prototype.init = function(context) {}
51+
loader.prototype.bundleEnd = function(context) {
52+
context.source.addContent(`FuseBox.import("fuse-box-aurelia-loader")`);
53+
context.source.addContent(`FuseBox.import("aurelia-bootstrapper")`);
54+
}
55+
return new loader();
56+
}
57+
```
58+
59+
60+
### How to develop/improve loader
61+
* run `node setup` to to npm install in root and sample folder
62+
* run `gulp watch` to start sample
63+
* run `gulp build` to create new build
Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,79 @@
1+
var gulp = require('gulp');
2+
var path = require('path');
3+
var runSequence = require('run-sequence');
4+
var autoLoadAureliaLoaders =function() {
5+
var loader = function(){}
6+
loader.prototype.init = function(context) {}
7+
loader.prototype.bundleEnd = function(context) {
8+
context.source.addContent(`FuseBox.import("fuse-box-aurelia-loader")`);
9+
context.source.addContent(`FuseBox.import("aurelia-bootstrapper")`);
10+
}
11+
return new loader();
12+
}
13+
14+
// so fusebox uses correct path
15+
process.env.PROJECT_ROOT = path.resolve(process.cwd(), './sample/')
16+
117
// builtin plugins
218
const {
319
RawPlugin,
420
FuseBox,
521
HTMLPlugin,
622
CSSPlugin,
723
Sparky
8-
} = require("fuse-box");
24+
} = require("../sample/node_modules/fuse-box");
925

26+
var TypeHelper = require('../sample/node_modules/fuse-box-typechecker').TypeHelper
1027

1128

29+
gulp.task('copy-fonts', () => {
30+
return gulp.src('node_modules/materialize-css/dist/fonts/**/**.**')
31+
.pipe(gulp.dest('fonts/'));
32+
});
1233

1334

14-
Sparky.task('copy-fonts', () => {
15-
Sparky.src('node_modules/materialize-css/dist/fonts/**/**.**')
16-
.dest('fonts/');
35+
// sample typechecker
36+
gulp.task('sample-typechecker', function () {
37+
// set correct dir first..
38+
process.chdir('./sample');
39+
var testWatch = TypeHelper({
40+
tsConfig: './tsconfig.json',
41+
name: 'Sample Watch'
42+
})
43+
testWatch.runWatch('./src')
44+
return true;
1745
});
1846

1947

48+
gulp.task('plugin-typechecker', function () {
49+
// set correct dir first..
50+
51+
var testWatch = TypeHelper({
52+
tsConfig: './tsconfig.json',
53+
name: 'Plugin Watch'
54+
})
55+
testWatch.runWatch('./src')
56+
return true;
57+
});
58+
2059

2160

61+
// this task will start fusebox
62+
gulp.task('fuse-sample', function () {
2263

23-
Sparky.task('dev', () => {
24-
// typechecker (minor bug first time when caching vendor bundle, its on my todo list(vegar)... just need to talk to fusebox team..)
25-
const TypeCheckPlugin = require('fuse-box-typechecker').TypeCheckPlugin;
64+
// init fusebox
2665
const fuse = FuseBox.init({
2766
homeDir: './src',
2867
output: './dist/$name.js',
2968
plugins: [
30-
TypeCheckPlugin(),
69+
autoLoadAureliaLoaders(),
3170
CSSPlugin(),
3271
HTMLPlugin(),
33-
RawPlugin(['.css', '.woff'])
72+
RawPlugin(['.css'])
3473
]
3574
});
3675

76+
3777
fuse.register('materialize-css-styles', {
3878
homeDir: 'node_modules/materialize-css/dist/css',
3979
main: 'materialize.css',
@@ -48,7 +88,7 @@ Sparky.task('dev', () => {
4888
instructions: '**/*.{html,css,js}'
4989
});
5090

51-
91+
// vendor bundle
5292
fuse.bundle("vendor")
5393
.cache(true)
5494
.instructions(`
@@ -61,15 +101,16 @@ Sparky.task('dev', () => {
61101
+ aurelia-fetch-client
62102
+ aurelia-pal-browser
63103
+ aurelia-animator-css
104+
+ fuse-box-css
64105
+ aurelia-logging-console
65106
+ aurelia-templating-binding
66107
+ aurelia-templating-resources
67108
+ aurelia-event-aggregator
68109
+ aurelia-history-browser
69110
+ aurelia-templating-router
70111
+ aurelia-materialize-bridge
71-
+ materialize-css-styles`)
72-
.alias({
112+
+ materialize-css-styles
113+
`).alias({
73114
'jQuery': 'jquery'
74115
})
75116
.shim({
@@ -93,54 +134,47 @@ Sparky.task('dev', () => {
93134
+ [**/*.{ts,html,css}]
94135
`);
95136

96-
97-
137+
// web server
98138
fuse.dev({
99139
root: './'
100140
});
101-
fuse.run();
102-
});
103-
104141

142+
// run
143+
return fuse.run()
144+
});
105145

106146

147+
// this task will start fusebox
148+
gulp.task('fuse-plugin', function () {
107149

108-
Sparky.task('loader', () => {
109-
// typechecker (minor bug first time when caching vendor bundle, its on my todo list(vegar)... just need to talk to fusebox team..)
110-
const TypeCheckPlugin = require('fuse-box-typechecker').TypeCheckPlugin;
150+
// package init
111151
const fuse = FuseBox.init({
112152
homeDir: '../src',
113153
output: './dist/$name.js',
114-
plugins: [
115-
TypeCheckPlugin(),
116-
CSSPlugin(),
117-
HTMLPlugin(),
118-
RawPlugin(['.css', '.woff'])
119-
],
154+
plugins: [],
120155
package: {
121156
name: "fuse-box-aurelia-loader",
122157
main: "fuse-box-aurelia-loader.ts"
123158
},
124159
});
125160

126161

127-
// app bundle
128-
// todo, we need to have vendor bundle and app bundle...
162+
// plugin bundle
129163
fuse.bundle('fuse-box-aurelia-loader')
130164
.watch().cache(false)
131165
.instructions(`
132166
[*.ts]
133-
134167
`).sourceMaps(true);
135168

136169

137-
138-
139-
fuse.run();
170+
//build file
171+
return fuse.run();
140172
});
141173

142174

143-
// run dev and loader build in parallell
144-
Sparky.task("run", ["&loader", "&dev"], () => {
145-
175+
// this task will start fusebox
176+
gulp.task('watch', function () {
177+
return runSequence(
178+
'fuse-plugin', 'fuse-sample', 'plugin-typechecker', 'sample-typechecker', 'copy-fonts'
179+
);
146180
});

dist/commonjs/fuse-box-aurelia-hmr-plugin.d.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

dist/commonjs/fuse-box-aurelia-hmr-plugin.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)