Last active
June 3, 2018 14:00
-
-
Save loveky/39facfc6ada23cb914554234fc6a14b7 to your computer and use it in GitHub Desktop.
create HtmlWebpackPlugin in a loop
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 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