Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path');
- const {CleanWebpackPlugin} = require('clean-webpack-plugin');
- const TerserPlugin = require('terser-webpack-plugin');
- conf = {
- entry: {
- site: './src/js/index.js',
- },
- output: {
- filename: './js/[name].js',
- path: path.resolve(__dirname, 'dist'),
- },
- module: {
- rules: [
- {
- test: /^[^\_+]*\.js$/,
- include: path.resolve(__dirname, 'src/js'),
- exclude: path.resolve(__dirname, 'node_modules'),
- use: {
- loader: 'babel-loader',
- options: {
- presets: ['@babel/preset-env'],
- },
- },
- },
- {
- test: /src[\\/]js[\\/]\_+.*\.js$/,
- include: path.resolve(__dirname, 'src/js'),
- exclude: path.resolve(__dirname, 'node_modules'),
- use: {
- loader: 'raw-loader',
- },
- },
- ],
- },
- optimization: {
- minimize: true,
- minimizer: [
- new TerserPlugin({
- include: /\.min.*\.js$/,
- cache: true,
- parallel: 4,
- sourceMap: true,
- terserOptions: {
- // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
- ie8: false,
- safari10: false,
- output: {
- beautify: false,
- comments: false,
- },
- },
- }),
- ],
- },
- plugins: [new CleanWebpackPlugin()],
- };
- module.exports = (env, options) => {
- let production = options.mode === 'production';
- conf.devtool = production ? false : 'eval-sourcemap';
- if (production) {
- conf.optimization.splitChunks = {
- chunks: 'all',
- // minSize: 100000,
- maxSize: 244000,
- maxInitialRequests: Infinity,
- cacheGroups: {
- vendor: {
- test: /[\\/]node_modules[\\/]/,
- enforce: true,
- reuseExistingChunk: true,
- name(module) {
- const packageName = module.context.match(
- /[\\/]node_modules[\\/](.*?)([\\/]|$)/
- )[1];
- return packageName.replace('@', '');
- },
- },
- nobandle: {
- test: /[\\/]src[\\/]js[\\/]\_+.*$/,
- enforce: true,
- reuseExistingChunk: true,
- name(module) {
- const packageName = module.rawRequest.match(
- /\.[\\/](.*?)(\.|$)/
- )[1];
- return packageName.replace('@', '');
- },
- },
- },
- };
- }
- return conf;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement