Skip to content

Instantly share code, notes, and snippets.

@loveky
Last active June 3, 2018 14:00
Show Gist options
  • Save loveky/39facfc6ada23cb914554234fc6a14b7 to your computer and use it in GitHub Desktop.
Save loveky/39facfc6ada23cb914554234fc6a14b7 to your computer and use it in GitHub Desktop.
create HtmlWebpackPlugin in a loop
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpackConfig = {
mode: 'development',
devtool: 'cheap-module-source-map',
entry: {
index: process.cwd() + '/src/index'
},
output: {
pathinfo: true,
path: process.cwd() + '/build',
filename: '[name].bundle.js',
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx'],
},
devServer: {
contentBase: '.'
},
module: {
strictExportPresence: true,
rules: [
{
test: /\.jsx?$/,
include: process.cwd() + '/src',
use: [
{
loader: 'babel-loader',
options: {
babelrc: false,
presets: ['@babel/preset-env', '@babel/preset-react'],
cacheDirectory: true,
},
},
],
},
],
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
__DEV__: true,
}),
new webpack.NoEmitOnErrorsPlugin()
],
};
webpackConfig.plugins.push(
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
chunks: ['index'],
inject: true,
})
);
module.exports = webpackConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment