Last active
October 27, 2017 14:46
-
-
Save gaganjakhotiya/834fffbc786c142e076b7452114f5dee to your computer and use it in GitHub Desktop.
Webpack Config for Lazy Loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin'); | |
const BUNDLE_LOADER_RULES = [ | |
{ | |
test: /.*\/admin\/.*\.widget\.jsx$/, | |
use: [ | |
{ | |
loader: 'bundle-loader', | |
options: { | |
name: 'admin', | |
lazy: true, | |
}, | |
}, | |
] | |
}, | |
{ | |
test: /.*\/user\/.*\.widget\.jsx$/, | |
use: [ | |
{ | |
loader: 'bundle-loader', | |
options: { | |
name: 'user', | |
lazy: true, | |
}, | |
}, | |
] | |
}, | |
] | |
module.exports = { | |
entry: { | |
vendor: [ | |
'react', | |
'react-dom', | |
], | |
index: './src/renderWidget', | |
}, | |
output: { | |
path: path.join(__dirname, 'build'), | |
filename: '[name].bundle.js', | |
publicPath: 'build/', | |
}, | |
module: { | |
rules: [ | |
...BUNDLE_LOADER_RULES, | |
{ | |
test: /\.jsx?$/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: [ | |
'env', | |
'react', | |
'es2017', | |
'stage-2', | |
], | |
}, | |
} | |
}, | |
] | |
}, | |
resolve: { | |
modules: ['node_modules'], | |
extensions: [ | |
'.js', | |
'.jsx', | |
] | |
}, | |
resolveLoader: { | |
moduleExtensions: ['-loader'], | |
}, | |
plugins: [ | |
new CommonsChunkPlugin({ | |
name: 'vendor', | |
filename: 'vendor.bundle.js', | |
}), | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment