webpack.prod.js

53 lines | 1.564 kB Blame History Raw Download
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 MonacoWebpackPlugin = require('monaco-editor-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]')
                    },
                    {
                        from: path.resolve(__dirname, 'manifest.json'),
                        to: path.resolve(__dirname, devFolderName, '[name][ext]')
                    }
                ]
            }
        ),
        new ReplaceInFileWebpackPlugin(
            [
                replaceVersionInHtmlOption
            ]
        )
    ]
});