Skip to content

Instantly share code, notes, and snippets.

@IniZio
Created April 29, 2017 10:51
Show Gist options
  • Save IniZio/89cdd33845337d7ff263691919b3d439 to your computer and use it in GitHub Desktop.
Save IniZio/89cdd33845337d7ff263691919b3d439 to your computer and use it in GitHub Desktop.
fuse 2 config
const {
FuseBox, Sparky,
BannerPlugin, ImageBase64Plugin, CSSResourcePlugin, CSSPlugin, TypeScriptHelpers, UglifyJSPlugin
} = require('fuse-box')
const { spawn } = require('child_process')
const isProduction = process.env.NODE_ENV === 'production'
const isElectron = process.env.TARGET === 'electron'
const fuse = FuseBox.init({
homeDir: 'src',
output: 'dist/$name.js',
sourceMaps: !isProduction,
cache: !isProduction,
shim: {
'react-native': { exports: 'undefined' }
},
plugins: [
CSSResourcePlugin({ inline: true }), CSSPlugin({ group: 'bundle.css' }),
ImageBase64Plugin(),
BannerPlugin(`// USThing Copyright 2017`),
].concat(isProduction && [
UglifyJSPlugin({
compress: { warnings: false, drop_console: true },
comments: false,
mangle: true,
minimize: true
})
])
})
let appChain = fuse.bundle('app').instructions('> [main.ts]')
Sparky.task('copy-html', () =>
Sparky.src('src/index.html').dest('dist/$name')
)
Sparky.task('copy-electron', () =>
Sparky.src('src/electron.js').dest('dist/$name')
)
Sparky.task('base', ['copy-html'], () =>
Sparky.start('copy-html')
)
Sparky.task('dev:web', ['base'], () => {
fuse.dev({ port: 8080, httpServer: true })
appChain
.watch().hmr()
return fuse.run()
})
Sparky.task('dev:electron', ['base', 'copy-electron'], () => {
fuse.dev({ port: 8080, httpServer: false })
appChain
.target('electron')
.watch().hmr()
return fuse.run().then(() => {
spawn(`${__dirname}/node_modules/electron/cli.js`, [`${__dirname}/dist/electron.js`])
})
})
Sparky.task('build:web', ['base'], () => {
return fuse.run()
})
Sparky.task('build:electron', ['base'], () => {
appChain
.target('electron')
return fuse.run().then(() => {})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment