Browse Source

Switch from Browserify to Webpack

1. The minimized versions of the library lib-jitsi-meet i.e. the file
   lib-jitsi-meet.js with the default configurations of Browserify and
   Webpack are, respectively, 614KB and 424KB. That's a reduction in
   file size of approximately 30%. While such a reduction may be
   achieved with Browserify, such a configuration would be non-default
   i.e. it would be more complex.

2. The build process of the library lib-jitsi-meet with Browserify is
   split into three distinct steps by package.json: transpile, version,
   and minimize. The transpile step produces a .js file and a source map
   which get consumed by the minimize step (as input files). A possible
   problem appears during the version step which modifies the .js file
   without modifying the respective source map. Thus, there is a risk
   that the source map of the minimized version of the library
   lib-jitsi-meet is broken. The Webpack approach carries out the
   version step in a way that precludes the possible breaking of the
   source map.

3. The introduction of ES2015 forced us to split the Babel-related parts
   of the build process out of package.json into start_browserify.js. As
   may be seen by comparing start_browserify.js and webpack.config.js,
   there are similarities. The advantage of Webpack is that the other
   parts of the build process are inside webpack.config.js as well. In
   other words, there is no split in the build process and there is less
   complexity.
dev1
Lyubomir Marinov 9 years ago
parent
commit
161f703e20
4 changed files with 82 additions and 32 deletions
  1. 5
    0
      .babelrc
  2. 16
    20
      package.json
  3. 0
    12
      start_browserify.js
  4. 61
    0
      webpack.config.babel.js

+ 5
- 0
.babelrc View File

1
+{
2
+    "presets": [
3
+        "es2015"
4
+    ]
5
+}

+ 16
- 20
package.json View File

4
   "description": "JS library for accessing Jitsi server side deployments",
4
   "description": "JS library for accessing Jitsi server side deployments",
5
   "repository": {
5
   "repository": {
6
     "type": "git",
6
     "type": "git",
7
-    "url": "git://github.com/jitsi/jitsi-meet"
7
+    "url": "git://github.com/jitsi/lib-jitsi-meet"
8
   },
8
   },
9
   "keywords": [
9
   "keywords": [
10
     "jingle",
10
     "jingle",
15
   "author": "",
15
   "author": "",
16
   "readmeFilename": "README.md",
16
   "readmeFilename": "README.md",
17
   "dependencies": {
17
   "dependencies": {
18
+    "async": "0.9.0",
19
+    "current-executing-script": "*",
18
     "events": "*",
20
     "events": "*",
21
+    "jitsi-meet-logger": "jitsi/jitsi-meet-logger",
22
+    "jssha": "1.5.0",
19
     "pako": "*",
23
     "pako": "*",
24
+    "retry": "0.6.1",
20
     "sdp-interop": "0.1.11",
25
     "sdp-interop": "0.1.11",
21
-    "sdp-transform": "1.5.*",
22
     "sdp-simulcast": "0.1.7",
26
     "sdp-simulcast": "0.1.7",
23
-    "async": "0.9.0",
24
-    "retry": "0.6.1",
25
-    "jssha": "1.5.0",
26
-    "jitsi-meet-logger": "git+https://github.com/jitsi/jitsi-meet-logger.git",
27
-    "strophe": "^1.2.2",
28
-    "strophejs-plugins": "^0.0.6",
27
+    "sdp-transform": "1.5.*",
29
     "socket.io-client": "1.3.6",
28
     "socket.io-client": "1.3.6",
30
-    "current-executing-script": "*"
29
+    "strophe": "^1.2.2",
30
+    "strophejs-plugins": "^0.0.6"
31
   },
31
   },
32
   "devDependencies": {
32
   "devDependencies": {
33
-    "babelify": "*",
34
-    "babel-preset-es2015": "*",
33
+    "babel-core": "*",
34
+    "babel-loader": "*",
35
     "babel-polyfill": "*",
35
     "babel-polyfill": "*",
36
-    "browserify": "11.1.x",
36
+    "babel-preset-es2015": "*",
37
+    "babel-register": "*",
37
     "jshint": "^2.8.0",
38
     "jshint": "^2.8.0",
38
     "precommit-hook": "^3.0.0",
39
     "precommit-hook": "^3.0.0",
39
-    "exorcist": "*",
40
-    "uglify-js": "2.4.24",
41
-    "watchify": "^3.7.0"
40
+    "string-replace-loader": "*",
41
+    "webpack": "*"
42
   },
42
   },
43
   "scripts": {
43
   "scripts": {
44
-    "install": "npm run browserify && npm run version && npm run uglifyjs",
45
-    "browserify": "node ./start_browserify.js | exorcist lib-jitsi-meet.js.map > lib-jitsi-meet.js && [ -s lib-jitsi-meet.js ]",
46
-    "version": "VERSION=`./get-version.sh` && echo lib-jitsi-meet version is:${VERSION} && sed -i'' -e s/{#COMMIT_HASH#}/${VERSION}/g lib-jitsi-meet.js",
47
-    "uglifyjs": "uglifyjs -p relative lib-jitsi-meet.js -o lib-jitsi-meet.min.js --source-map lib-jitsi-meet.min.map --in-source-map lib-jitsi-meet.js.map",
48
-    "watch": "watchify JitsiMeetJS.js -s JitsiMeetJS -o lib-jitsi-meet.js -v",
44
+    "install": "webpack && webpack -p",
49
     "lint": "jshint .",
45
     "lint": "jshint .",
50
     "validate": "npm ls"
46
     "validate": "npm ls"
51
   },
47
   },

+ 0
- 12
start_browserify.js View File

1
-var browserify = require("browserify");
2
-var babelify = require("babelify");
3
-
4
-browserify("./JitsiMeetJS.js", {
5
-    debug: true,
6
-    standalone: "JitsiMeetJS"
7
-}).transform(babelify.configure({
8
-  ignore: [
9
-      /\/node_modules\/(?!lib-jitsi-meet\/)/,
10
-      "modules/RTC/adapter.screenshare.js"],
11
-  presets: ["es2015"]
12
-})).bundle().pipe(process.stdout);

+ 61
- 0
webpack.config.babel.js View File

1
+/* global __dirname */
2
+
3
+import child_process from 'child_process'; // eslint-disable-line camelcase
4
+import path from 'path';
5
+import process from 'process';
6
+
7
+const minimize
8
+    = process.argv.indexOf('-p') !== -1
9
+        || process.argv.indexOf('--optimize-minimize') !== -1;
10
+
11
+export default {
12
+    devtool: 'source-map',
13
+    entry: {
14
+        'lib-jitsi-meet': './JitsiMeetJS.js'
15
+    },
16
+    module: {
17
+        loaders: [ {
18
+            // Version this build of the lib-jitsi-meet library.
19
+
20
+            include: path.resolve(__dirname, './JitsiMeetJS.js'),
21
+            loader: 'string-replace',
22
+            query: {
23
+                flags: 'g',
24
+                replace:
25
+                    child_process.execSync( // eslint-disable-line camelcase
26
+                            path.resolve(__dirname, './get-version.sh'))
27
+
28
+                        // The type of the return value of
29
+                        // child_process.execSync is either Buffer or String.
30
+                        .toString()
31
+
32
+                            // Shells may automatically append CR and/or LF
33
+                            // characters to the output.
34
+                            .trim(),
35
+                search: '{#COMMIT_HASH#}'
36
+            },
37
+            test: /\.js$/
38
+        }, {
39
+            // Transpile ES2015 (aka ES6) to ES5.
40
+
41
+            exclude: [
42
+                path.resolve(__dirname, './modules/RTC/adapter.screenshare.js'),
43
+                path.resolve(__dirname, './node_modules/')
44
+            ],
45
+            loader: 'babel',
46
+            test: /\.js$/
47
+        } ]
48
+    },
49
+    node: {
50
+        // Allow the use of the real filename of the module being executed. By
51
+        // default Webpack does not leak path-related information and provides a
52
+        // value that is a mock (/index.js).
53
+        __filename: true
54
+    },
55
+    output: {
56
+        filename: `[name]${minimize ? '.min' : ''}.js`,
57
+        library: 'JitsiMeetJS',
58
+        libraryTarget: 'umd',
59
+        sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
60
+    }
61
+};

Loading…
Cancel
Save