Przeglądaj źródła

Switch from Browserify to Webpack

j8
Lyubomir Marinov 8 lat temu
rodzic
commit
f6662745d1
5 zmienionych plików z 180 dodań i 118 usunięć
  1. 8
    0
      .babelrc
  2. 3
    2
      .jshintignore
  3. 31
    37
      Makefile
  4. 17
    79
      package.json
  5. 121
    0
      webpack.config.babel.js

+ 8
- 0
.babelrc Wyświetl plik

@@ -0,0 +1,8 @@
1
+{
2
+    "plugins": [
3
+        "transform-object-rest-spread"
4
+    ],
5
+    "presets": [
6
+        "es2015"
7
+    ]
8
+}

+ 3
- 2
.jshintignore Wyświetl plik

@@ -1,4 +1,5 @@
1
-node_modules
2
-libs
3 1
 debian
2
+libs
3
+node_modules
4 4
 analytics.js
5
+webpack.config.babel.js

+ 31
- 37
Makefile Wyświetl plik

@@ -1,20 +1,17 @@
1
-NPM = npm
2
-BROWSERIFY = ./node_modules/.bin/browserify
3
-NODE_SASS = ./node_modules/.bin/node-sass
4
-UGLIFYJS = ./node_modules/.bin/uglifyjs
5
-EXORCIST = ./node_modules/.bin/exorcist
1
+BUILD_DIR = build
6 2
 CLEANCSS = ./node_modules/.bin/cleancss
7
-STYLES_MAIN = css/main.scss
8
-STYLES_UNSUPPORTED_BROWSER = css/unsupported_browser.scss
9
-STYLES_BUNDLE = css/all.bundle.css
10
-STYLES_DESTINATION = css/all.css
11 3
 DEPLOY_DIR = libs
12
-BROWSERIFY_FLAGS = -d
13
-OUTPUT_DIR = .
14 4
 LIBJITSIMEET_DIR = node_modules/lib-jitsi-meet/
15
-IFRAME_API_DIR = ./modules/API/external
5
+NODE_SASS = ./node_modules/.bin/node-sass
6
+NPM = npm
7
+OUTPUT_DIR = .
8
+STYLES_BUNDLE = css/all.bundle.css
9
+STYLES_DESTINATION = css/all.css
10
+STYLES_MAIN = css/main.scss
11
+STYLES_UNSUPPORTED_BROWSER = css/unsupported_browser.scss
12
+WEBPACK = ./node_modules/.bin/webpack
16 13
 
17
-all: update-deps compile compile-iframe-api uglify uglify-iframe-api deploy clean
14
+all: update-deps compile deploy clean
18 15
 
19 16
 # FIXME: there is a problem with node-sass not correctly installed (compiled)
20 17
 # a quick fix to make sure it is installed on every update
@@ -23,13 +20,11 @@ update-deps:
23 20
 	$(NPM) update && $(NPM) install node-sass
24 21
 
25 22
 compile:
26
-	$(BROWSERIFY) $(BROWSERIFY_FLAGS) -e app.js -s APP | $(EXORCIST) $(OUTPUT_DIR)/app.bundle.js.map > $(OUTPUT_DIR)/app.bundle.js
27
-
28
-compile-iframe-api:
29
-	$(BROWSERIFY) $(BROWSERIFY_FLAGS) -e $(IFRAME_API_DIR)/external_api.js -s JitsiMeetExternalAPI | $(EXORCIST) $(OUTPUT_DIR)/external_api.js.map > $(OUTPUT_DIR)/external_api.js
23
+	$(WEBPACK)
24
+	$(WEBPACK) -p
30 25
 
31 26
 clean:
32
-	rm -f $(OUTPUT_DIR)/app.bundle.* $(OUTPUT_DIR)/external_api.*
27
+	rm -fr $(BUILD_DIR)
33 28
 
34 29
 deploy: deploy-init deploy-appbundle deploy-lib-jitsi-meet deploy-css deploy-local
35 30
 
@@ -37,20 +32,26 @@ deploy-init:
37 32
 	mkdir -p $(DEPLOY_DIR)
38 33
 
39 34
 deploy-appbundle:
40
-	cp $(OUTPUT_DIR)/app.bundle.min.js $(OUTPUT_DIR)/app.bundle.min.map \
41
-	$(OUTPUT_DIR)/app.bundle.js $(OUTPUT_DIR)/app.bundle.js.map \
42
-	$(OUTPUT_DIR)/external_api.js.map $(OUTPUT_DIR)/external_api.js \
43
-	$(OUTPUT_DIR)/external_api.min.map $(OUTPUT_DIR)/external_api.min.js \
44
-	$(OUTPUT_DIR)/analytics.js \
45
-	$(DEPLOY_DIR)
35
+	cp \
36
+		$(BUILD_DIR)/app.bundle.js \
37
+		$(BUILD_DIR)/app.bundle.js.map \
38
+		$(BUILD_DIR)/app.bundle.min.js \
39
+		$(BUILD_DIR)/app.bundle.min.map \
40
+		$(BUILD_DIR)/external_api.js \
41
+		$(BUILD_DIR)/external_api.js.map \
42
+		$(BUILD_DIR)/external_api.min.js \
43
+		$(BUILD_DIR)/external_api.min.map \
44
+		$(OUTPUT_DIR)/analytics.js \
45
+		$(DEPLOY_DIR)
46 46
 
47 47
 deploy-lib-jitsi-meet:
48
-	cp $(LIBJITSIMEET_DIR)/lib-jitsi-meet.min.js \
49
-	$(LIBJITSIMEET_DIR)/lib-jitsi-meet.min.map \
50
-	$(LIBJITSIMEET_DIR)/lib-jitsi-meet.js \
51
-	$(LIBJITSIMEET_DIR)/lib-jitsi-meet.js.map \
52
-	$(LIBJITSIMEET_DIR)/connection_optimization/external_connect.js \
53
-	$(DEPLOY_DIR)
48
+	cp \
49
+		$(LIBJITSIMEET_DIR)/lib-jitsi-meet.js \
50
+		$(LIBJITSIMEET_DIR)/lib-jitsi-meet.js.map \
51
+		$(LIBJITSIMEET_DIR)/lib-jitsi-meet.min.js \
52
+		$(LIBJITSIMEET_DIR)/lib-jitsi-meet.min.map \
53
+		$(LIBJITSIMEET_DIR)/connection_optimization/external_connect.js \
54
+		$(DEPLOY_DIR)
54 55
 
55 56
 deploy-css:
56 57
 	$(NODE_SASS) css/unsupported_browser.scss css/unsupported_browser.css ; \
@@ -61,13 +62,6 @@ deploy-css:
61 62
 deploy-local:
62 63
 	([ ! -x deploy-local.sh ] || ./deploy-local.sh)
63 64
 
64
-uglify:
65
-	$(UGLIFYJS) -p relative $(OUTPUT_DIR)/app.bundle.js -o $(OUTPUT_DIR)/app.bundle.min.js --source-map $(OUTPUT_DIR)/app.bundle.min.map --in-source-map $(OUTPUT_DIR)/app.bundle.js.map
66
-
67
-uglify-iframe-api:
68
-	$(UGLIFYJS) -p relative $(OUTPUT_DIR)/external_api.js -o $(OUTPUT_DIR)/external_api.min.js --source-map $(OUTPUT_DIR)/external_api.min.map --in-source-map $(OUTPUT_DIR)/external_api.js.map
69
-
70
-
71 65
 source-package:
72 66
 	mkdir -p source_package/jitsi-meet/css && \
73 67
 	cp -r *.js *.html connection_optimization favicon.ico fonts images libs sounds LICENSE lang source_package/jitsi-meet && \

+ 17
- 79
package.json Wyświetl plik

@@ -22,13 +22,13 @@
22 22
     "bootstrap": "3.1.1",
23 23
     "events": "*",
24 24
     "i18next-client": "1.7.7",
25
-    "jQuery-Impromptu": "git+https://github.com/trentrichardson/jQuery-Impromptu.git#v6.0.0",
25
+    "jQuery-Impromptu": "trentrichardson/jQuery-Impromptu#v6.0.0",
26 26
     "jquery": "~2.1.1",
27 27
     "jquery-contextmenu": "*",
28 28
     "jquery-ui": "1.10.5",
29 29
     "jssha": "1.5.0",
30 30
     "jws": "*",
31
-    "lib-jitsi-meet": "git+https://github.com/jitsi/lib-jitsi-meet.git",
31
+    "lib-jitsi-meet": "jitsi/lib-jitsi-meet",
32 32
     "postis": "^2.2.0",
33 33
     "retry": "0.6.1",
34 34
     "strophe": "^1.2.2",
@@ -36,101 +36,39 @@
36 36
     "toastr": "^2.0.3"
37 37
   },
38 38
   "devDependencies": {
39
+    "babel-core": "*",
40
+    "babel-loader": "*",
41
+    "babel-plugin-transform-object-rest-spread": "*",
39 42
     "babel-polyfill": "*",
40 43
     "babel-preset-es2015": "*",
41
-    "babelify": "*",
42
-    "browserify": "11.1.x",
43
-    "browserify-css": "^0.9.2",
44
-    "browserify-shim": "^3.8.10",
44
+    "babel-register": "*",
45 45
     "clean-css": "*",
46
-    "exorcist": "*",
46
+    "css-loader": "*",
47
+    "expose-loader": "*",
48
+    "file-loader": "*",
49
+    "imports-loader": "*",
47 50
     "jshint": "2.8.0",
48 51
     "node-sass": "^3.8.0",
49 52
     "precommit-hook": "3.0.0",
50
-    "uglify-js": "2.4.24",
51
-
52
-    "babel-core": "*",
53
-    "babel-loader": "*",
54
-    "babel-register": "*",
55 53
     "string-replace-loader": "*",
54
+    "style-loader": "*",
56 55
     "webpack": "*"
57 56
   },
58 57
   "license": "Apache-2.0",
59 58
   "scripts": {
60
-    "lint": "./node_modules/.bin/jshint .",
59
+    "lint": "jshint .",
61 60
     "validate": "npm ls"
62 61
   },
63 62
   "pre-commit": [
64 63
     "lint"
65 64
   ],
66
-  "browserify": {
67
-    "transform": [
68
-      "browserify-shim",
69
-      "browserify-css",
70
-      [
71
-        "babelify",
72
-        {
73
-          "ignore": "node_modules"
74
-        }
75
-      ]
76
-    ]
77
-  },
78
-  "babel": {
79
-    "presets": [
80
-      "es2015"
81
-    ]
82
-  },
83 65
   "browser": {
84
-    "jquery": "./node_modules/jquery/dist/jquery.js",
85
-    "jquery-ui": "./node_modules/jquery-ui/jquery-ui.js",
86
-    "strophe": "./node_modules/strophe/strophe.js",
66
+    "aui-css": "./node_modules/@atlassian/aui/dist/aui/css/aui.min.css",
67
+    "aui-experimental-css": "./node_modules/@atlassian/aui/dist/aui/css/aui-experimental.min.css",
68
+    "autosize": "./node_modules/autosize/build/jquery.autosize.js",
69
+    "popover": "./node_modules/bootstrap/js/popover.js",
87 70
     "strophe-disco": "./node_modules/strophejs-plugins/disco/strophe.disco.js",
88 71
     "strophe-caps": "./node_modules/strophejs-plugins/caps/strophe.caps.jsonly.js",
89
-    "toastr": "./node_modules/toastr/toastr.js",
90
-    "tooltip": "./node_modules/bootstrap/js/tooltip.js",
91
-    "popover": "./node_modules/bootstrap/js/popover.js",
92
-    "jQuery-Impromptu": "./node_modules/jQuery-Impromptu/dist/jquery-impromptu.js",
93
-    "autosize": "./node_modules/autosize/build/jquery.autosize.js",
94
-    "aui": "./node_modules/@atlassian/aui/dist/aui/js/aui.js",
95
-    "aui-experimental": "./node_modules/@atlassian/aui/dist/aui/js/aui-experimental.js",
96
-    "aui-css": "./node_modules/@atlassian/aui/dist/aui/css/aui.min.css",
97
-    "aui-experimental-css": "./node_modules/@atlassian/aui/dist/aui/css/aui-experimental.min.css"
98
-  },
99
-  "browserify-shim": {
100
-    "jquery": [
101
-      "$"
102
-    ],
103
-    "strophe": {
104
-      "exports": "Strophe",
105
-      "depends": [
106
-        "jquery:$"
107
-      ]
108
-    },
109
-    "strophe-disco": {
110
-      "depends": [
111
-        "strophe:Strophe"
112
-      ]
113
-    },
114
-    "tooltip": {
115
-      "depends": "jquery:jQuery"
116
-    },
117
-    "popover": {
118
-      "depends": "jquery:jQuery"
119
-    },
120
-    "jQuery-Impromptu": {
121
-      "depends": "jquery:jQuery"
122
-    },
123
-    "aui-experimental": {
124
-      "depends": "aui:AJS"
125
-    },
126
-    "jquery-contextmenu": {
127
-      "depends": "jquery:jQuery"
128
-    },
129
-    "autosize": {
130
-      "depends": "jquery:jQuery"
131
-    },
132
-    "browserify-css": {
133
-        "autoInject": true
134
-    }
72
+    "tooltip": "./node_modules/bootstrap/js/tooltip.js"
135 73
   }
136 74
 }

+ 121
- 0
webpack.config.babel.js Wyświetl plik

@@ -0,0 +1,121 @@
1
+import path from 'path';
2
+import process from 'process';
3
+import webpack from 'webpack';
4
+
5
+const aui_css
6
+    = path.resolve(__dirname, './node_modules/@atlassian/aui/dist/aui/css/');
7
+const minimize
8
+    = process.argv.indexOf('-p') != -1
9
+        || process.argv.indexOf('--optimize-minimize') != -1;
10
+const strophe = /\/node_modules\/strophe(js-plugins)?\/.*\.js$/;
11
+
12
+// The base Webpack configuration to bundle the JavaScript artifacts of
13
+// jitsi-meet such as app.bundle.js and external_api.js.
14
+const config = {
15
+    devtool: 'source-map',
16
+    module: {
17
+        loaders: [{
18
+            // Transpile ES2015 (aka ES6) to ES5.
19
+
20
+            exclude: [
21
+                path.resolve(__dirname, './modules/RTC/adapter.screenshare.js'),
22
+                path.resolve(__dirname, './node_modules/')
23
+            ],
24
+            loader: 'babel',
25
+            test: /\.js$/
26
+        },{
27
+            // Expose jquery as the globals $ and jQuery because it is expected
28
+            // to be available in such a form by multiple jitsi-meet
29
+            // dependencies including AUI, lib-jitsi-meet.
30
+
31
+            loader: 'expose?$!expose?jQuery',
32
+            test: /\/node_modules\/jquery\/.*\.js$/
33
+        },{
34
+            // Disable AMD for the Strophe.js library or its imports will fail
35
+            // at runtime.
36
+
37
+            loader: 'imports?define=>false&this=>window',
38
+            test: strophe
39
+        },{
40
+            // Allow CSS to be imported into JavaScript.
41
+
42
+            loaders: [
43
+                'style',
44
+                'css'
45
+            ],
46
+            test: /\.css$/
47
+        },{
48
+            // Emit the static assets of AUI such as images that are referenced
49
+            // by CSS into the output path.
50
+
51
+            include: aui_css,
52
+            loader: 'file',
53
+            query: {
54
+                context: aui_css,
55
+                name: '[path][name].[ext]'
56
+            },
57
+            test: /\.(gif|png|svg)$/
58
+        }],
59
+        noParse: [
60
+            // Do not parse the files of the Strophe.js library or at least
61
+            // parts of the properties of the Strophe global variable will be
62
+            // missing and strophejs-plugins will fail at runtime.
63
+            strophe
64
+        ]
65
+    },
66
+    node: {
67
+        // Allow the use of the real filename of the module being executed. By
68
+        // default Webpack does not leak path-related information and provides a
69
+        // value that is a mock (/index.js).
70
+        __filename: true
71
+    },
72
+    output: {
73
+        filename: '[name]' + (minimize ? '.min' : '') + '.js',
74
+        libraryTarget: 'umd',
75
+        path: path.resolve(__dirname, './build'),
76
+        sourceMapFilename: '[name].' + (minimize ? 'min' : 'js') + '.map'
77
+    },
78
+    resolve: {
79
+        alias: {
80
+            aui:
81
+                '@atlassian/aui/dist/aui/js/aui'
82
+                    + (minimize ? '.min' : '')
83
+                    + '.js',
84
+            'aui-experimental':
85
+                '@atlassian/aui/dist/aui/js/aui-experimental'
86
+                    + (minimize ? '.min' : '')
87
+                    + '.js',
88
+            jquery: 'jquery/dist/jquery' + (minimize ? '.min' : '') + '.js',
89
+            'jQuery-Impromptu':
90
+                'jQuery-Impromptu/dist/jquery-impromptu'
91
+                    + (minimize ? '.min' : '')
92
+                    + '.js',
93
+        },
94
+        packageAlias: 'browser'
95
+    }
96
+};
97
+
98
+export default [{
99
+    // The Webpack configuration to bundle app.bundle.js (aka APP).
100
+
101
+    ...config,
102
+    entry: {
103
+       'app.bundle': './app.js'
104
+    },
105
+    output: {
106
+        ...config.output,
107
+        library: 'APP'
108
+    }
109
+}, {
110
+    // The Webpack configuration to bundle external_api.js (aka
111
+    // JitsiMeetExternalAPI).
112
+
113
+    ...config,
114
+    entry: {
115
+       'external_api': './modules/API/external/external_api.js'
116
+    },
117
+    output: {
118
+        ...config.output,
119
+        library: 'JitsiMeetExternalAPI'
120
+    }
121
+}];

Ładowanie…
Anuluj
Zapisz