48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
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(
|
|
{
|
|
patterns: [
|
|
{
|
|
from: path.resolve(__dirname, 'index.html'),
|
|
to: path.resolve(__dirname, prodFolderName, '[name].[ext]')
|
|
}
|
|
]
|
|
}
|
|
),
|
|
new ReplaceInFileWebpackPlugin(
|
|
[
|
|
replaceVersionInHtmlOption
|
|
]
|
|
)
|
|
]
|
|
}); |