/
fuse.js
111 lines (98 loc) · 2.06 KB
/
fuse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
let fuse
const {
FuseBox,
ConsolidatePlugin,
WebIndexPlugin,
StylusPlugin,
CSSResourcePlugin,
CSSPlugin,
JSONPlugin,
PostCSSPlugin,
QuantumPlugin,
VueComponentPlugin
} = require('fuse-box')
const {
src,
task,
context
} = require('fuse-box/sparky')
class Builder {
constructor () {
this.isProduction = false
}
setProduction () {
this.isProduction = true
}
getFuse () {
return FuseBox.init({
homeDir: 'src',
target: 'browser@es5',
output: 'dist/$name.js',
modulesFolder: 'src/shims',
sourceMaps: !this.isProduction,
useTypescriptCompiler: true,
allowSyntheticDefaultImports: true,
plugins: [
VueComponentPlugin({
style: [
CSSResourcePlugin({
resolve: (file) => {
return `/img/${file}`
},
macros: { static: `${__dirname}/src/assets/img/`, fonts: `${__dirname}/src/assets/fonts/` },
dist: `${__dirname}/dist/img/`
}),
CSSPlugin()
]
}),
CSSPlugin(),
JSONPlugin(),
WebIndexPlugin({
template: 'src/index.html'
}),
this.isProduction && QuantumPlugin({
bakeApiIntoBundle: 'app',
uglify: false,
// css: true,
treeshake: true,
ensureES5: true
})
]
})
}
createBundle (fuse) {
const app = fuse.bundle('app').sourceMaps( !this.isProduction )
if (!this.isProduction) {
app.hmr()
app.watch()
}
app.instructions('> index.js')
return app
}
}
context(Builder)
task('copy-assets', async (context) => {
await src('./*.*', { base: './src/static/' }).dest('dist/').exec()
await src('./*.json', { base: './src/lang/' }).dest('dist/').exec()
} )
task('clean', async () => {
await src('./dist')
.clean('dist/')
.exec()
})
task('default', ['clean', 'copy-assets'], async (context) => {
fuse = context.getFuse()
fuse.dev({
open: !!process.env.npm_config_open,
port: 5555,
fallback: 'index.html'
})
context.createBundle(fuse)
await fuse.run()
})
task('build', ['clean', 'copy-assets'], async (context) => {
context.setProduction()
const fuse = context.getFuse()
context.createBundle(fuse)
await fuse.run()
})