[英]How to set diffrent plugin options with webpack-merge
base https://webpack.js.org/guides/production/基地https://webpack.js.org/guides/production/
I want to use diffrent html template in webpack.dev.js & webpack.prod.js我想在webpack.dev.js和webpack.prod.js 中使用不同的 html 模板
webpack.common.js webpack.common.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
app: './src/index.js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'Production'
}),
]
};
webpack.dev.js webpack.dev.js
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: 'development',
plugins: [
new HtmlWebpackPlugin({
template:'./public/index-dev.html',
})
]
});
webpack.prod.js webpack.prod.js
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: 'production',
plugins:
new HtmlWebpackPlugin({
template:'./public/index.html',
})
]
});
report ReferenceError: HtmlWebpackPlugin is not defined when npm run with these config报告ReferenceError:使用这些配置运行 npm时未定义 HtmlWebpackPlugin
With out an explicit require/import you cann't directly access HtmlWebpackPlugin of anything else from one config file in another.如果没有明确的要求/导入,您将无法从另一个配置文件中直接访问其他任何内容的 HtmlWebpackPlugin。 Merge only joins the config portion not the whole files.
合并只加入配置部分而不是整个文件。
Therefor you must have const HtmlWebpackPlugin = require('html-webpack-plugin');
因此你必须有
const HtmlWebpackPlugin = require('html-webpack-plugin');
in all files where HtmlWebpackPlugin is used.在使用 HtmlWebpackPlugin 的所有文件中。
webpage-merge is does not merge all file data just the module.exports object itself.网页合并不合并所有文件数据,只是 module.exports 对象本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.