Procházet zdrojové kódy

feat(build) migrate to webpack 5

dev1
Saúl Ibarra Corretgé před 3 roky
rodič
revize
bf0d5b5ec2
5 změnil soubory, kde provedl 1100 přidání a 4301 odebrání
  1. 2
    2
      karma.conf.js
  2. 978
    4192
      package-lock.json
  3. 7
    6
      package.json
  4. 81
    77
      webpack-shared-config.js
  5. 32
    24
      webpack.config.js

+ 2
- 2
karma.conf.js Zobrazit soubor

@@ -10,7 +10,7 @@ module.exports = function(config) {
10 10
 
11 11
         // frameworks to use
12 12
         // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13
-        frameworks: [ 'jasmine' ],
13
+        frameworks: [ 'jasmine', 'webpack' ],
14 14
 
15 15
         // list of files / patterns to load in the browser
16 16
         files: [
@@ -60,6 +60,6 @@ module.exports = function(config) {
60 60
         // if true, Karma captures browsers, runs the tests and exits
61 61
         singleRun: true,
62 62
 
63
-        webpack: require('./webpack-shared-config')
63
+        webpack: require('./webpack-shared-config')(false /* minimize */, false /* analyzeBundle */)
64 64
     });
65 65
 };

+ 978
- 4192
package-lock.json
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 7
- 6
package.json Zobrazit soubor

@@ -52,15 +52,16 @@
52 52
     "karma-chrome-launcher": "3.1.0",
53 53
     "karma-jasmine": "3.1.1",
54 54
     "karma-sourcemap-loader": "0.3.7",
55
-    "karma-webpack": "4.0.2",
56
-    "string-replace-loader": "2.1.1",
57
-    "webpack": "4.43.0",
58
-    "webpack-bundle-analyzer": "3.4.1",
59
-    "webpack-cli": "3.3.11"
55
+    "karma-webpack": "5.0.0",
56
+    "process": "0.11.10",
57
+    "string-replace-loader": "3.0.3",
58
+    "webpack": "5.57.1",
59
+    "webpack-bundle-analyzer": "4.4.2",
60
+    "webpack-cli": "4.9.0"
60 61
   },
61 62
   "scripts": {
62 63
     "lint": "eslint .",
63
-    "postinstall": "webpack -p",
64
+    "postinstall": "webpack",
64 65
     "test": "karma start karma.conf.js",
65 66
     "test-watch": "karma start karma.conf.js --no-single-run",
66 67
     "validate": "npm ls",

+ 81
- 77
webpack-shared-config.js Zobrazit soubor

@@ -1,90 +1,94 @@
1 1
 /* global __dirname */
2 2
 
3 3
 const process = require('process');
4
+const { ProvidePlugin } = require('webpack');
4 5
 const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
5 6
 
6
-const analyzeBundle = process.argv.indexOf('--analyze-bundle') !== -1;
7 7
 
8
-const minimize
9
-    = process.argv.indexOf('-p') !== -1
10
-        || process.argv.indexOf('--optimize-minimize') !== -1;
8
+module.exports = (minimize, analyzeBundle) => {
9
+    return {
10
+        // The inline-source-map is used to allow debugging the unit tests with Karma
11
+        devtool: minimize ? 'source-map' : 'inline-source-map',
12
+        mode: minimize ? 'production' : 'development',
13
+        module: {
14
+            rules: [ {
15
+                // Version this build of the lib-jitsi-meet library.
11 16
 
12
-module.exports = {
13
-    // The inline-source-map is used to allow debugging the unit tests with Karma
14
-    devtool: minimize ? 'source-map' : 'inline-source-map',
15
-    mode: minimize ? 'production' : 'development',
16
-    module: {
17
-        rules: [ {
18
-            // Version this build of the lib-jitsi-meet library.
17
+                loader: 'string-replace-loader',
18
+                options: {
19
+                    flags: 'g',
20
+                    replace:
21
+                        process.env.LIB_JITSI_MEET_COMMIT_HASH || 'development',
22
+                    search: '{#COMMIT_HASH#}'
23
+                },
24
+                test: `${__dirname}/JitsiMeetJS.js`
25
+            }, {
26
+                // Transpile ES2015 (aka ES6) to ES5.
19 27
 
20
-            loader: 'string-replace-loader',
21
-            options: {
22
-                flags: 'g',
23
-                replace:
24
-                    process.env.LIB_JITSI_MEET_COMMIT_HASH || 'development',
25
-                search: '{#COMMIT_HASH#}'
26
-            },
27
-            test: `${__dirname}/JitsiMeetJS.js`
28
-        }, {
29
-            // Transpile ES2015 (aka ES6) to ES5.
30
-
31
-            loader: 'babel-loader',
32
-            options: {
33
-                presets: [
34
-                    [
35
-                        '@babel/preset-env',
28
+                exclude: [
29
+                    new RegExp(`${__dirname}/node_modules/(?!@jitsi/js-utils)`)
30
+                ],
31
+                loader: 'babel-loader',
32
+                options: {
33
+                    presets: [
34
+                        [
35
+                            '@babel/preset-env',
36 36
 
37
-                        // Tell babel to avoid compiling imports into CommonJS
38
-                        // so that webpack may do tree shaking.
39
-                        {
40
-                            modules: false,
37
+                            // Tell babel to avoid compiling imports into CommonJS
38
+                            // so that webpack may do tree shaking.
39
+                            {
40
+                                modules: false,
41 41
 
42
-                            // Specify our target browsers so no transpiling is
43
-                            // done unnecessarily. For browsers not specified
44
-                            // here, the ES2015+ profile will be used.
45
-                            targets: {
46
-                                chrome: 58,
47
-                                electron: 2,
48
-                                firefox: 54,
49
-                                safari: 11
42
+                                // Specify our target browsers so no transpiling is
43
+                                // done unnecessarily. For browsers not specified
44
+                                // here, the ES2015+ profile will be used.
45
+                                targets: {
46
+                                    chrome: 58,
47
+                                    electron: 2,
48
+                                    firefox: 54,
49
+                                    safari: 11
50
+                                }
50 51
                             }
51
-                        }
52
+                        ]
53
+                    ],
54
+                    plugins: [
55
+                        '@babel/plugin-proposal-class-properties',
56
+                        '@babel/plugin-proposal-optional-chaining',
57
+                        '@babel/plugin-proposal-export-namespace-from',
58
+                        '@babel/plugin-proposal-nullish-coalescing-operator'
52 59
                     ]
53
-                ],
54
-                plugins: [
55
-                    '@babel/plugin-proposal-class-properties',
56
-                    '@babel/plugin-proposal-optional-chaining',
57
-                    '@babel/plugin-proposal-export-namespace-from',
58
-                    '@babel/plugin-proposal-nullish-coalescing-operator'
59
-                ]
60
-            },
61
-            test: /\.js$/
62
-        } ]
63
-    },
64
-    node: {
65
-        // Allow the use of the real filename of the module being executed. By
66
-        // default Webpack does not leak path-related information and provides a
67
-        // value that is a mock (/index.js).
68
-        __filename: true
69
-    },
70
-    optimization: {
71
-        concatenateModules: minimize
72
-    },
73
-    output: {
74
-        filename: `[name]${minimize ? '.min' : ''}.js`,
75
-        path: process.cwd(),
76
-        sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
77
-    },
78
-    performance: {
79
-        hints: minimize ? 'error' : false,
80
-        maxAssetSize: 750 * 1024,
81
-        maxEntrypointSize: 750 * 1024
82
-    },
83
-    plugins: [
84
-        analyzeBundle
85
-            && new BundleAnalyzerPlugin({
86
-                analyzerMode: 'disabled',
87
-                generateStatsFile: true
88
-            })
89
-    ].filter(Boolean)
60
+                },
61
+                test: /\.js$/
62
+            } ]
63
+        },
64
+        node: {
65
+            // Allow the use of the real filename of the module being executed. By
66
+            // default Webpack does not leak path-related information and provides a
67
+            // value that is a mock (/index.js).
68
+            __filename: true
69
+        },
70
+        optimization: {
71
+            concatenateModules: minimize
72
+        },
73
+        output: {
74
+            filename: `[name]${minimize ? '.min' : ''}.js`,
75
+            sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
76
+        },
77
+        performance: {
78
+            hints: minimize ? 'error' : false,
79
+            maxAssetSize: 750 * 1024,
80
+            maxEntrypointSize: 750 * 1024
81
+        },
82
+        plugins: [
83
+            analyzeBundle
84
+                && new BundleAnalyzerPlugin({
85
+                    analyzerMode: 'disabled',
86
+                    generateStatsFile: true
87
+                }),
88
+            !minimize
89
+                && new ProvidePlugin({
90
+                    process: 'process/browser'
91
+                })
92
+        ].filter(Boolean)
93
+    };
90 94
 };

+ 32
- 24
webpack.config.js Zobrazit soubor

@@ -1,28 +1,36 @@
1 1
 const process = require('process');
2 2
 
3
-const config = require('./webpack-shared-config');
3
+const sharedConfig = require('./webpack-shared-config');
4 4
 
5
-module.exports = [
6
-    Object.assign({}, config, {
7
-        entry: {
8
-            'lib-jitsi-meet': './index.js'
9
-        },
10
-        output: Object.assign({}, config.output, {
11
-            library: 'JitsiMeetJS',
12
-            libraryTarget: 'umd'
13
-        })
14
-    }),
15
-    {
16
-        entry: {
17
-            worker: './modules/e2ee/Worker.js'
18
-        },
19
-        mode: 'production',
20
-        output: {
21
-            filename: 'lib-jitsi-meet.e2ee-worker.js',
22
-            path: process.cwd()
23
-        },
24
-        optimization: {
25
-            minimize: false
5
+module.exports = (_env, argv) => {
6
+    // Despite what whe docs say calling webpack with no arguments results in mode not being set.
7
+    const mode = typeof argv.mode === 'undefined' ? 'production' : argv.mode;
8
+    const config
9
+        = sharedConfig(mode === 'production' /* minimize */, Boolean(process.env.ANALYZE_BUNDLE) /* analyzeBundle */);
10
+
11
+    return [
12
+        Object.assign({}, config, {
13
+            entry: {
14
+                'lib-jitsi-meet': './index.js'
15
+            },
16
+            output: Object.assign({}, config.output, {
17
+                library: 'JitsiMeetJS',
18
+                libraryTarget: 'umd',
19
+                path: process.cwd()
20
+            })
21
+        }),
22
+        {
23
+            entry: {
24
+                worker: './modules/e2ee/Worker.js'
25
+            },
26
+            mode,
27
+            output: {
28
+                filename: 'lib-jitsi-meet.e2ee-worker.js',
29
+                path: process.cwd()
30
+            },
31
+            optimization: {
32
+                minimize: false
33
+            }
26 34
         }
27
-    }
28
-];
35
+    ];
36
+};

Načítá se…
Zrušit
Uložit