Skip to content
Snippets Groups Projects
Select Git revision
  • 4934450665eb0a17b6a1ec78cb109e716282b916
  • master default protected
  • 1.31
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
  • 4.23.1
  • 4.23.0
  • 4.22.3
  • 4.22.2
  • 4.22.1
  • 4.22.0
  • 4.21.0
  • 4.20.1
  • 4.20.0
  • 4.19.0
  • 4.18.0
23 results

select.mjs

Blame
  • webpack.config.js 1.43 KiB
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    const TerserPlugin = require("terser-webpack-plugin");
    const pkg = require('./package.json');
    const webpack = require('webpack');
    const fs = require('fs');
    const name = pkg.name;
    let plugins = [];
    let optimization = {};
    
    
    module.exports = (env = {}) => {
        if (env.production) {
            optimization.minimizer = [
                new TerserPlugin({
                    parallel: true,
                })
            ];
            plugins = [
                new webpack.BannerPlugin(`${name} - ${pkg.version}`),
            ]
        } else {
            const index = 'index.html';
            const indexDev = '_' + index;
            plugins.push(new HtmlWebpackPlugin({
                template: fs.existsSync(indexDev) ? indexDev : index
            }));
        }
    
        return {
            mode: env.production ? 'production' : 'development',
            entry: './source',
            output: {
                filename: `./${name}.min.js`,
                library: name,
                libraryTarget: 'umd',
            },
            module: {
                rules: [
                    {
                        test: /\.js$/,
                        include: /source/,
                        use: {
                            loader: 'babel-loader',
                        }
                    },
                ],
            },
            externals: {'grapesjs': 'grapesjs'},
            optimization: optimization,
            plugins: plugins,
            watchOptions: {
                ignored: /node_modules/
            }
        };
    };