From 317b10fcafb0ab98d90efcf9a059042fdd634ea0 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Wed, 23 Nov 2016 00:47:39 +0530 Subject: [PATCH] feat(bundler): allow creating a bundle with common code --- README.md | 2 +- src/configure-bundler.js | 6 ++++++ src/quik-cli.js | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 41c8513..2d2f454 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ The `--production` option performs minification on the resulting bundle. You can You can provide multiple entry points as arguments. In that case, you can use `[name]` to get the name of the entry point while specifying an output file, ```sh -quik --bundle file1.js file2.js --output [name].bundle.js +quik --bundle file1.js file2.js --output [name].bundle.js --common common.bundle.js ``` Sourcemap files are automatically generated when generating bundles. diff --git a/src/configure-bundler.js b/src/configure-bundler.js index 05de7d4..2b383d2 100644 --- a/src/configure-bundler.js +++ b/src/configure-bundler.js @@ -33,6 +33,12 @@ export default async function(options) { filename: OUTPUTFILE, sourceMapFilename: OUTPUTFILE + '.map', }, + plugins: options.common ? [ + new webpack.optimize.CommonsChunkPlugin({ + name: options.common, + filename: options.common, + }), + ] : null, entry, })); } diff --git a/src/quik-cli.js b/src/quik-cli.js index 7edbc31..5f6b10f 100644 --- a/src/quik-cli.js +++ b/src/quik-cli.js @@ -44,6 +44,10 @@ const argv = yargs type: 'string', description: 'Name of the output file', }, + common: { + type: 'string', + description: 'Name of file to contain common code in case of multiple entries', + }, production: { type: 'boolean', default: false, @@ -84,6 +88,7 @@ if (argv.init) { bundle({ root: process.cwd(), entry: argv.bundle.map(it => './' + it), + common: argv.common, output: argv.output, production: argv.production, sourcemaps: argv.sourcemaps,