diff --git a/lib/webpack.config.base.js b/lib/webpack.config.base.js index 9882aba..249e718 100644 --- a/lib/webpack.config.base.js +++ b/lib/webpack.config.base.js @@ -43,7 +43,7 @@ module.exports = function (type, options) { devtool: type === 'watch' ? 'cheap-module-eval-source-map' : 'source-map', entry: options.entry ? objectString(options.entry) : 'src/index', output: { - path: cwd('build'), + path: cwd(options.dest || 'build'), filename: 'bundle.js', publicPath: './' }, @@ -96,14 +96,31 @@ module.exports = function (type, options) { fallbacks: true }) ], - plugins: [ + plugins: [] + } + // for both watch and build + // set format + if (options.format === 'umd') { + config.output.libraryTarget = 'umd' + config.output.library = options.umd + } else if (options.format === 'cjs') { + config.output.libraryTarget = 'commonjs2' + } + // set target + if (options.target) { + config.target = options.target + } + // add html plugin if not targeted in commonjs + if (options.format !== 'cjs') { + config.plugins.push( new HtmlWebpackPlugin(Object.assign({}, { title: options.title || 'Tooling', template: dir('lib/index.jade'), inject: false }, toolingConfig.index)) - ] + ) } + if (type === 'watch') { // inject client page for hmr if (typeof config.entry === 'string') { diff --git a/readme.md b/readme.md index 09d11de..273ba82 100644 --- a/readme.md +++ b/readme.md @@ -73,6 +73,11 @@ Options: |-u/--use|Set the framework you use, eg: `react`, `vue`. `vue` by default| |--ai/--auto-install|(**Buggy**) Automatically install missing dependencies when editing| |--title|Set html title| +|--format|Set bundle format, available options are `cjs` `umd`, default is `iife`| +|-t/--target|Set webpack target| +|-d/--dest|Set bundled file dest directory, default is `./build`| + +Run `tooling -h` `tooling watch -h` `tooling build -h` to see more usage. **Set up custom index.html in `package.json`**. see usage at [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin) @@ -82,7 +87,7 @@ Options: "tooling": { "index": { "title": "tooling index", - "template": "src/index.template" + "template": "src/index.jade" } } } diff --git a/tooling b/tooling index c7d9180..8d1f365 100755 --- a/tooling +++ b/tooling @@ -13,6 +13,7 @@ program.version(pkg.version) program .command('watch') + .description('hot reloading mode') .option('-e, --entry [webpackEntry]', 'Set webpack entry') .option('-p, --port [serverPort]', 'Change port of server') .option('--bs, --browser-sync [port]', 'Toggle browserSync') @@ -20,13 +21,19 @@ program .option('-u, --use [usePresetsFor]', 'Use presets for React or Vue or the default config') .option('--ai, --auto-install', 'Automatically install missing dependencies when editing') .option('--title [htmlTitle]', 'Set title for output html') + .option('--format [bundleFormat]', 'Set bundle format') + .option('--target [webpackTarget]', 'Set webpack target') .action(watch) program .command('build') + .description('build mode') .option('-e, --entry [webpackEntry]', 'Set webpack entry"') .option('-u, --use [usePresetsFor]', 'Use presets for React or Vue') .option('--title [htmlTitle]', 'Set title for output html') + .option('--format [bundleFormat]', 'Set bundle format') + .option('-t, --target [webpackTarget]', 'Set webpack target') + .option('-d, --dest [bundleDestDir]', 'Set bundled file dest directory') .action(build) program.parse(process.argv)