Skip to content

Instantly share code, notes, and snippets.

@bytrangle
Created March 13, 2020 09:06
Show Gist options
  • Save bytrangle/a6bb798b272eb42b9d30327f56acb6c7 to your computer and use it in GitHub Desktop.
Save bytrangle/a6bb798b272eb42b9d30327f56acb6c7 to your computer and use it in GitHub Desktop.
This Webpack configuration will output Javascript and CSS files to different directories. Example is dist/js/main.js, dist/css/main.csss, dist/css/bootstrap.css
module.exports = {
mode: 'development',
entry: path.resolve(__dirname, 'static/index.js'),
output: {
filename: 'js/[name].js',
path: path.resolve(__dirname, 'dist/js'),
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
return `${packageName.replace('@', '')}`;
},
reuseExistingChunk: true,
},
},
},
},
module: {
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/[name].css',
}),
new HtmlWebpackPlugin({
title: 'Keywording',
template: './static/template.html',
}),
new BundleAnalyzerPlugin(),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment