-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultsFuseBox.js
64 lines (56 loc) · 1.66 KB
/
DefaultsFuseBox.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
// instructions = '>' + pm.in.homeToEntry + ''
// bundle.includeKeys().forEach(includes => instructions += ' +' + includes)
// bundle.excludeKeys().forEach(external => instructions += ' -' + external)
//
// let config = {
// debug: true,
// log: true,
// cache: context.settings.cache,
// homeDir: bundle.pm.homeDir(),
// outFile: bundle.pm.outFile(),
// package: context.name,
// globals: {[context.name]: '*'},
// plugins: builder.loaders.get(),
// }
const log = require('fliplog')
const {Hub} = require('fliphub-core')
module.exports = class PresetDefaultsFuseBox extends Hub {
// instructions
setArgs(args) {
if (args) this.args = args
return this
}
init(workflow) {
if (this.args)
workflow.current.config.flips({from: 'webpack', to: 'fusebox'})
}
decorate(context) {
const {to} = context.config.getFlips()
if (to !== 'fusebox') return
}
toFuseBox(config, workflow) {
const {HTMLPlugin, JSONPlugin} = require('fuse-box')
workflow.current.bundler.config.outputToString()
let entry = config.get('entry')
let output = config.get('output')
const root = config.get('root')
if (this.args && typeof entry === 'string') {
entry = this.args.replace('entry', entry)
entry = entry.replace('./', '').replace(root, '')
}
// this.args &&
if (typeof output === 'string') {
output = output
.replace('./', '')
.replace(root, '')
.replace('[name]', '$name')
}
// log.quick(this.args, instructions, root, workflow)
// log.quick({entry, output})
return {
plugins: [HTMLPlugin({default: true}), JSONPlugin()],
entry,
output,
}
}
}