Skip to content

Instantly share code, notes, and snippets.

@teologov
Forked from robertknight/Build.md
Created November 30, 2016 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teologov/bd24183a0763e209dc2bdd8f31bcd5cb to your computer and use it in GitHub Desktop.
Save teologov/bd24183a0763e209dc2bdd8f31bcd5cb to your computer and use it in GitHub Desktop.
Minimal Webpack DllPlugin example
var square = require('./vendor');
console.log(square(7));
var webpack = require('webpack');
module.exports = {
entry: {
app: ['./app'],
},
output: {
filename: 'app.bundle.js',
path: 'build/',
},
plugins: [new webpack.DllReferencePlugin({
context: '.',
manifest: require('./build/vendor-manifest.json'),
})]
};

Compile with:

webpack --config vendor.webpack.config.js
webpack --config app.webpack.config.js

Use with the following index.html

<script src="build/vendor.bundle.js"></script>
<script src="build/app.bundle.js"></script>
function square(n) {
return n*n;
}
module.exports = square;
var webpack = require('webpack');
module.exports = {
entry: {
vendor: ['./vendor'],
},
output: {
filename: 'vendor.bundle.js',
path: 'build/',
library: 'vendor_lib',
},
plugins: [new webpack.DllPlugin({
name: 'vendor_lib',
path: 'build/vendor-manifest.json',
})]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment