Skip to content

Instantly share code, notes, and snippets.

@adamhenson
Last active February 27, 2019 14:10
Show Gist options
  • Save adamhenson/96ff7e07239d890a157e407863977d0b to your computer and use it in GitHub Desktop.
Save adamhenson/96ff7e07239d890a157e407863977d0b to your computer and use it in GitHub Desktop.
Webpack config with Loadable Component
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