← All changes
|
classes/Visualizer/Gutenberg/webpack.config.js
+93
-78
3.10.13
→
3.11.10
View file →
| @@ -1,93 +1,108 @@ | ||
| 1 | -const webpack = require( 'webpack' ); | |
| 1 | +const webpack = require('webpack'); | |
| 2 | 2 | const NODE_ENV = process.env.NODE_ENV || 'development'; |
| 3 | -const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' ); | |
| 3 | +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
| 4 | +const TerserPlugin = require('terser-webpack-plugin'); | |
| 4 | 5 | |
| 5 | 6 | module.exports = { |
| 6 | - externals: { | |
| 7 | + externals: { | |
| 7 | 8 | 'lodash': 'lodash' |
| 8 | 9 | }, |
| 9 | - mode: NODE_ENV, | |
| 10 | - entry: './src/index.js', | |
| 11 | - output: { | |
| 12 | - path: __dirname, | |
| 13 | - filename: './build/block.js', | |
| 14 | - chunkFilename: './build/[name].js' | |
| 15 | - }, | |
| 16 | - module: { | |
| 17 | - rules: [ | |
| 18 | - { | |
| 19 | - test: /.js?$/, | |
| 20 | - use: [ { | |
| 21 | - loader: 'babel-loader', | |
| 22 | - options: { | |
| 23 | - presets: [ '@babel/preset-env' ], | |
| 24 | - plugins: [ | |
| 25 | - '@babel/plugin-transform-async-to-generator', | |
| 26 | - '@babel/plugin-proposal-object-rest-spread', | |
| 27 | - [ | |
| 28 | - '@babel/plugin-transform-react-jsx', { | |
| 29 | - 'pragma': 'wp.element.createElement' | |
| 30 | - } | |
| 31 | - ] | |
| 32 | - ] | |
| 33 | - } | |
| 34 | - }, | |
| 35 | - 'eslint-loader' ], | |
| 36 | - exclude: /node_modules/ | |
| 37 | - }, | |
| 38 | - { | |
| 39 | - test: /\.(css|scss)$/, | |
| 40 | - use: [ { | |
| 41 | - loader: MiniCssExtractPlugin.loader | |
| 42 | - }, | |
| 43 | - 'css-loader', | |
| 44 | - { | |
| 45 | - loader: 'postcss-loader', | |
| 46 | - options: { | |
| 47 | - plugins: [ | |
| 48 | - require( 'autoprefixer' ) | |
| 49 | - ] | |
| 50 | - } | |
| 51 | - }, | |
| 52 | - { | |
| 53 | - loader: 'sass-loader', | |
| 54 | - query: { | |
| 55 | - outputStyle: | |
| 56 | - 'production' === process.env.NODE_ENV ? 'compressed' : 'nested' | |
| 57 | - } | |
| 58 | - } ] | |
| 59 | - }, | |
| 60 | - { | |
| 61 | - test: /\.(png|jpe?g|gif)$/, | |
| 62 | - use: [ | |
| 63 | - { | |
| 64 | - loader: 'file-loader', | |
| 65 | - options: { | |
| 66 | - name: './[name].[ext]' | |
| 67 | - } | |
| 68 | - } | |
| 69 | - ] | |
| 70 | - } | |
| 71 | - ] | |
| 72 | - }, | |
| 73 | - optimization: { | |
| 10 | + mode: NODE_ENV, | |
| 11 | + entry: { | |
| 12 | + block: './src/index.js' | |
| 13 | + }, | |
| 14 | + output: { | |
| 15 | + path: __dirname, | |
| 16 | + filename: './build/[name].js' | |
| 17 | + }, | |
| 18 | + module: { | |
| 19 | + rules: [ | |
| 20 | + { | |
| 21 | + test: /\.js$/, | |
| 22 | + use: { | |
| 23 | + loader: 'babel-loader', | |
| 24 | + options: { | |
| 25 | + presets: ['@babel/preset-env'], | |
| 26 | + plugins: [ | |
| 27 | + '@babel/plugin-transform-async-to-generator', | |
| 28 | + '@babel/plugin-proposal-object-rest-spread', | |
| 29 | + [ | |
| 30 | + '@babel/plugin-transform-react-jsx', { | |
| 31 | + 'pragma': 'wp.element.createElement' | |
| 32 | + } | |
| 33 | + ] | |
| 34 | + ] | |
| 35 | + } | |
| 36 | + }, | |
| 37 | + exclude: /node_modules/ | |
| 38 | + }, | |
| 39 | + { | |
| 40 | + test: /\.(css|scss)$/, | |
| 41 | + use: [ | |
| 42 | + { | |
| 43 | + loader: MiniCssExtractPlugin.loader | |
| 44 | + }, | |
| 45 | + 'css-loader', | |
| 46 | + { | |
| 47 | + loader: 'postcss-loader', | |
| 48 | + options: { | |
| 49 | + postcssOptions: { | |
| 50 | + plugins: [ | |
| 51 | + require('autoprefixer') | |
| 52 | + ] | |
| 53 | + } | |
| 54 | + } | |
| 55 | + }, | |
| 56 | + { | |
| 57 | + loader: 'sass-loader', | |
| 58 | + options: { | |
| 59 | + implementation: require('sass'), | |
| 60 | + sassOptions: { | |
| 61 | + outputStyle: NODE_ENV === 'production' ? 'compressed' : 'expanded' | |
| 62 | + } | |
| 63 | + } | |
| 64 | + } | |
| 65 | + ] | |
| 66 | + }, | |
| 67 | + { | |
| 68 | + test: /\.(png|jpe?g|gif)$/, | |
| 69 | + use: [ | |
| 70 | + { | |
| 71 | + loader: 'file-loader', | |
| 72 | + options: { | |
| 73 | + name: './[name].[ext]' | |
| 74 | + } | |
| 75 | + } | |
| 76 | + ] | |
| 77 | + } | |
| 78 | + ] | |
| 79 | + }, | |
| 80 | + optimization: { | |
| 74 | 81 | splitChunks: { |
| 75 | 82 | cacheGroups: { |
| 76 | 83 | handsontable: { |
| 77 | 84 | name: 'handsontable', |
| 78 | 85 | test: /[\\/]node_modules[\\/]handsontable/, |
| 79 | - chunks: 'all' | |
| 86 | + chunks: 'all', | |
| 87 | + enforce: true | |
| 80 | 88 | } |
| 81 | 89 | } |
| 82 | 90 | } |
| 83 | 91 | }, |
| 84 | - plugins: [ | |
| 85 | - new webpack.DefinePlugin({ | |
| 86 | - 'process.env.NODE_ENV': JSON.stringify( NODE_ENV ) | |
| 87 | - }), | |
| 88 | - new MiniCssExtractPlugin({ | |
| 89 | - filename: './build/block.css', | |
| 90 | - chunkFilename: './build/[name].css' | |
| 91 | - }) | |
| 92 | - ] | |
| 92 | + plugins: [ | |
| 93 | + new webpack.DefinePlugin({ | |
| 94 | + 'process.env.NODE_ENV': JSON.stringify(NODE_ENV) | |
| 95 | + }), | |
| 96 | + new MiniCssExtractPlugin({ | |
| 97 | + filename: './build/[name].css' | |
| 98 | + }), | |
| 99 | + new TerserPlugin({ | |
| 100 | + terserOptions: { | |
| 101 | + format: { | |
| 102 | + comments: false // Disable comments | |
| 103 | + } | |
| 104 | + }, | |
| 105 | + extractComments: false // Prevents LICENSE.txt generation | |
| 106 | + }) | |
| 107 | + ] | |
| 93 | 108 | }; |