webpack.prod.js
Home
/
webpack.prod.js
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const path = require('path');
const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const prodFolderName = "prod-dist";
const replaceVersionInHtmlOption = {
//set ?v= with new date in html files for production
dir: path.join(__dirname, prodFolderName),
test: /\.html$/,
rules: [
{
search: /((\?|\&)v\=)(.+?)(?=\"|\'|\&)/ig,
replace: (match) => {
return match.toString().substr(0, 3) +
+new Date();
}
}
]
};
module.exports = merge(common, {
mode: "production",
output: {
path: path.resolve(__dirname, prodFolderName),
publicPath: "/",
filename: 'main.js'
},
plugins: [
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '*.html'),
to: path.resolve(__dirname, prodFolderName, '[name].[ext]')
}
]),
new ReplaceInFileWebpackPlugin(
[
replaceVersionInHtmlOption
]
)
]
});