How to use terser-webpack-plugin - 10 common examples

To help you get started, we’ve selected a few terser-webpack-plugin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleChromeLabs / worker-plugin / test / _util.js View on Github external
export function watchWebpack (fixture, { output, plugins, context, ...config } = {}) {
  context = context || path.resolve(__dirname, 'fixtures', fixture);
  const compiler = webpack({
    mode: 'production',
    context,
    entry: './entry.js',
    output: {
      publicPath: 'dist/',
      path: path.resolve(context, 'dist'),
      ...(output || {})
    },
    optimization: {
      minimize: true,
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            mangle: false,
            output: {
              beautify: true
            }
          },
          sourceMap: false
        })
      ]
    },
    plugins: plugins || []
  });
  // compiler.watch({});
  compiler.doRun = () => run(compiler.run.bind(compiler));
  return compiler;
}
github bennymeg / nx-electron / src / utils / electron.config.ts View on Github external
target: 'node',
    node: false
  };

  if (options.optimization) {
    webpackConfig.optimization = {
      minimize: false,
      concatenateModules: false
    };
  }

  if (options.obfuscate) {
    const obfuscationOptimization = {
      minimize: true,
      minimizer: [
        new TerserPlugin({
          chunkFilter: (chunk) => {
            // Exclude uglification for the `vendor` chunk
            if (chunk.name === 'vendor') {
              return false;
            }
  
            return true;
          },
          parallel: true,
          terserOptions: {
            mangle: true,
            keep_fnames: false,
            toplevel: true,
          }
        }),
      ],
github reworkjs / reworkjs / src / internals / webpack / features / optimize.js View on Github external
hints: 'warning',
      },
      optimization: {
        removeAvailableModules: true,
        splitChunks: {
          // don't generate names for long term caching
          // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
          name: false,
        },
        minimize: true,
        minimizer: [
          // minimize CSS
          new OptimizeCSSAssetsPlugin({}),

          // minimize JS
          new TerserPlugin({
            parallel: true,
            cache: true,

            // preserve LICENSE comments (*!, /**!, @preserve or @license) for legal stuff but extract them
            // to their own file to reduce bundle size.
            extractComments: true,

            terserOptions: {
              compress: {
                warnings: false,

                // TODO set to 6/7/8 if .browserlistrc supports it
                // Will use newer features to optimize
                ecma: 5,
              },
github lnlfps / symph-joy / build / webpack.js View on Github external
const config: any = {
    splitChunks: {
      cacheGroups: {
        default: false,
        vendors: false
      }
    }
  }

  if (dev) {
    return config
  }

  // Terser is a better uglifier
  config.minimizer = [new TerserPlugin({
    parallel: true,
    sourceMap: false,
    cache: true
  })]

  // Only enabled in production
  // This logic will create a commons bundle
  // with modules that are used in 50% of all pages
  config.splitChunks.chunks = 'all'
  config.splitChunks.cacheGroups.commons = {
    name: 'commons',
    chunks: 'all',
    minChunks: totalPages > 2 ? totalPages * 0.5 : 2
  }

  return config
github airbnb / nimbus / packages / config-webpack / src / index.ts View on Github external
headers: {
        'Service-Worker-Allowed': '/',
      },
      historyApiFallback: true,
      hot: true,
      port, // This can be a unix socket path so a string is valid
      watchOptions: {
        ignored: /node_modules/,
      },
    },

    optimization: {
      runtimeChunk: 'single',
      minimize: PROD,
      minimizer: [
        new TerserPlugin({
          sourceMap: sourceMaps,
        }),
      ],
    },

    performance: false,

    stats: !PROD,
  };
}
github yuanqing / create-figma-plugin / packages / build / src / create-webpack-config.js View on Github external
resolve(process.cwd(), '..', '..', 'node_modules'), // Lerna monorepo
        process.cwd(),
        'node_modules'
      ],
      extensions: ['.js', '.json']
    },
    devtool: isDevelopment ? 'inline-cheap-module-source-map' : 'none',
    stats: 'errors-only',
    plugins: [
      new webpack.EnvironmentPlugin({
        NODE_ENV: mode
      })
    ],
    optimization: {
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            output: {
              comments: false
            }
          },
          extractComments: false
        })
      ]
    }
  }
}
github elastic / kibana / src / optimize / dynamic_dll_plugin / dll_config_model.js View on Github external
function optimized(config) {
  return webpackMerge(
    {
      mode: 'production',
      optimization: {
        minimizer: [
          new TerserPlugin({
            // Apply the same logic used to calculate the
            // threadLoaderPool workers number to spawn
            // the parallel processes on terser
            parallel: config.threadLoaderPoolConfig.workers,
            sourceMap: false,
            terserOptions: {
              compress: {
                // The following is required for dead-code the removal
                // check in React DevTools
                //
                // default
                unused: true,
                dead_code: true,
                conditionals: true,
                evaluate: true,
github davidbailey00 / ninetales / packages / build / src / index.js View on Github external
function createWebpackConfig(env, entries) {
  const { development, sourceFilePattern, buildDirs } = config;
  const preset = { client: "browser", server: "node" }[env];

  const webpackConfig = {
    mode: development ? "development" : "production",
    devtool: development ? "eval-source-map" : false,
    entry: entries[env],
    output: {
      filename: "[chunkhash].js",
      path: resolve(buildDirs[env]),
    },
    optimization: {
      minimizer: [new TerserJSPlugin(), new OptimizeCSSAssetsPlugin()],
      usedExports: true,
      splitChunks: {
        chunks: "all",
      },
    },
    plugins: [
      new MiniCssExtractPlugin({
        filename: "[contenthash].css",
      }),
    ],
    module: {
      rules: [
        {
          test: file => file.endsWith(".css"),
          use: [
            {
github swagger-api / swagger-js / webpack / _config-builder.js View on Github external
compiler =>
            new TerserPlugin({
              cache: true,
              sourceMap: sourcemaps,
              terserOptions: {
                mangle: !!mangle,
              },
            }).apply(compiler),
        ],
github Kunstmaan / KunstmaanBundlesCMS / src / Kunstmaan / GeneratorBundle / Resources / SensioGeneratorBundle / skeleton / layout / groundcontrol / bin / config / webpack.config.default.js View on Github external
function shouldOptimize({ optimize = false }) {
    if (optimize) {
        return {
            minimizer: [new TerserPlugin({
                terserOptions: {
                    mangle: true,
                    sourceMap: true,
                },
            })],
        };
    }
}

terser-webpack-plugin

Terser plugin for webpack

MIT
Latest version published 9 days ago

Package Health Score

89 / 100
Full package analysis

Popular terser-webpack-plugin functions