Skip to content

Instantly share code, notes, and snippets.

@alber70g
Last active March 26, 2018 10:28
Show Gist options
  • Save alber70g/fb71982e2fbd4079c3a2bb6d24278eea to your computer and use it in GitHub Desktop.
Save alber70g/fb71982e2fbd4079c3a2bb6d24278eea to your computer and use it in GitHub Desktop.
Sample
const {
FuseBox,
JSONPlugin,
EnvPlugin,
QuantumPlugin,
} = require('fuse-box');
const { TypeHelper } = require('fuse-box-typechecker');
const typeHelper = TypeHelper({
tsConfig: './tsconfig.json',
basePath: './',
// tsLint:'./tslint.json', // you do not have to do tslint.. just here to show how.
name: 'TS typechecker',
});
// Use process.env.NODE_ENV in your code to check and remove dead code for production builds
const NODE_ENV = process.env.NODE_ENV || 'development';
const isProduction = NODE_ENV === 'production';
const fuse = FuseBox.init({
homeDir: '.',
output: 'build/$name.js',
// sourceMaps: !isProduction,
shim: {
// Adding global shims this way
promise: {
source: 'node_modules/es6-promise/dist/es6-promise.auto.min.js',
exports: 'Promise',
},
},
plugins: [
QuantumPlugin({ treeshake: true, uglify: true, bakeApiIntoBundle: 'main' }),
EnvPlugin({}),
JSONPlugin(),
],
});
let fuseChain = fuse
.bundle('main')
.target('browser')
.instructions(`> src/index.ts`);
if (!isProduction) {
// To use HMR use this, reload=true is to make sure it reloads
// fully instead of letting the app replace 'hot modules'.
// fuseChain = fuseChain.hmr({
// reload: true,
// socketURI: `ws://localhost:${3000}`,
// });
// run typechecker whenever something changes (it's parallel from building Typescript)
fuseChain.watch('src/**').completed(proc => {
console.log('\x1b[36m%s\x1b[0m', 'client bundled');
// run the type checking
typeHelper.runSync();
});
// Proxying stuff
// fuse.dev(
// {
// open: true,
// root: './',
// port: 3000,
// proxy: proxy,
// },
// server => {
// // run something here that's the proxy, e.g. an express app
// }
// );
}
fuse.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment