Last active
February 27, 2019 14:10
-
-
Save adamhenson/96ff7e07239d890a157e407863977d0b to your computer and use it in GitHub Desktop.
Webpack config with Loadable Component
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
import webpack from 'webpack'; | |
import path from 'path'; | |
const common = { | |
// imagine your configuration here | |
}; | |
const plugins = [ | |
// imagine your Babel plugins here | |
]; | |
const presets = [ | |
// imagine your Babel presets here | |
]; | |
export default { | |
entry: [ | |
'@babel/polyfill', | |
'./src/client', | |
], | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: [ | |
{ | |
loader: 'babel-loader', | |
options: { | |
plugins: [ | |
// this is the important part... | |
'@loadable/babel-plugin', | |
...plugins, | |
], | |
presets, | |
}, | |
}, | |
], | |
}, | |
...common.plugins.module.rules, | |
], | |
}, | |
plugins: [ | |
// this is too... | |
new LoadablePlugin(), | |
new webpack.DefinePlugin({ | |
LOADABLE_STATS: JSON.stringify(path.resolve(__dirname, '../build/loadable-stats.json')), | |
}), | |
...common.plugins, | |
], | |
optimization: { | |
// https://webpack.js.org/plugins/split-chunks-plugin/#optimization-splitchunks | |
splitChunks: { | |
chunks: 'all', | |
}, | |
}, | |
...common, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment