webpack.prod.js

53 lines | 1.593 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 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: {
        globalObject: 'self',
		filename: '[name].bundle.js',
        path: path.resolve(__dirname, prodFolderName, "codeeditor"),
        publicPath: "/"
    },
    plugins: [
        new CopyWebpackPlugin(
            {
                patterns: [
                    {
                        from: path.resolve(__dirname, 'codeeditor-app/static'),
                        to: path.resolve(__dirname, prodFolderName, 'codeeditor', '[name][ext]')
                    },
                    {
                        from: path.resolve(__dirname, 'outputframe-app/static'),
                        to: path.resolve(__dirname, prodFolderName, 'outputframe', '[name][ext]')
                    }
                ]
            }
        ),
        new ReplaceInFileWebpackPlugin(
            [
                replaceVersionInHtmlOption
            ]
        )
    ]
});