|
1 | 1 | const path = require('path'); |
2 | 2 | const fs = require('fs'); |
| 3 | +const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); |
| 4 | +const TerserPlugin = require('terser-webpack-plugin'); |
3 | 5 | const HtmlWebpackPlugin = require('html-webpack-plugin'); |
4 | 6 |
|
5 | 7 | function Plugin() {} |
@@ -30,23 +32,51 @@ module.exports = { |
30 | 32 | entry: path.resolve(__dirname, './src/iframe.js'), |
31 | 33 | output: { |
32 | 34 | filename: 'sandbox-[contenthash].js', |
33 | | - chunkFilename: '[name]-[contenthash].bundle.js', |
| 35 | + chunkFilename: 'sandbox-[name]-[contenthash].bundle.js', |
34 | 36 | path: path.resolve(__dirname, '../../kolibri/core/content/static/sandbox'), |
35 | 37 | }, |
36 | | - mode: 'none', |
| 38 | + mode: 'production', |
37 | 39 | module: { |
38 | 40 | rules: [ |
39 | 41 | { |
40 | | - test: /\.js$/, |
| 42 | + test: /\.(js|mjs)$/, |
41 | 43 | loader: 'babel-loader', |
42 | | - exclude: { and: [/(uuid|core-js)/, { not: [/\.(esm\.js|mjs)$/] }] }, |
| 44 | + exclude: [ |
| 45 | + // From: https://webpack.js.org/loaders/babel-loader/#exclude-libraries-that-should-not-be-transpiled |
| 46 | + // \\ for Windows, / for macOS and Linux |
| 47 | + /node_modules[\\/]core-js/, |
| 48 | + /node_modules[\\/]webpack[\\/]buildin/, |
| 49 | + ], |
| 50 | + options: { |
| 51 | + // Let babel auto-detect ES vs CommonJS |
| 52 | + sourceType: 'unambiguous', |
| 53 | + }, |
43 | 54 | }, |
44 | 55 | ], |
45 | 56 | }, |
46 | 57 | optimization: { |
47 | 58 | splitChunks: { |
48 | 59 | minChunks: 2, |
49 | 60 | }, |
| 61 | + minimizer: [ |
| 62 | + new TerserPlugin({ |
| 63 | + parallel: true, |
| 64 | + terserOptions: { |
| 65 | + mangle: { |
| 66 | + safari10: true, |
| 67 | + }, |
| 68 | + safari10: true, |
| 69 | + output: { |
| 70 | + comments: false, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }), |
| 74 | + new CssMinimizerPlugin({ |
| 75 | + minimizerOptions: { |
| 76 | + preset: ['default', { reduceIdents: false, zindex: false }], |
| 77 | + }, |
| 78 | + }), |
| 79 | + ], |
50 | 80 | }, |
51 | 81 | plugins: [ |
52 | 82 | new Plugin(), |
|
0 commit comments