Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: webpack_runner.js

Issue 29549786: Issue 5535 - Replace our module system with webpack (Closed)
Patch Set: Produce all bundles in one Node.js process to speed things up Created Oct. 4, 2017, 4:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webpack.config.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 const path = require("path");
19 const process = require("process");
20
21 const MemoryFS = require("memory-fs");
22 const webpack = require("webpack");
23
24 let {BOUNDARY, BUNDLES, EXTENSION_PATH,
25 RESOLVE_PATHS} = JSON.parse(process.argv[2]);
26
27 // Copied from adblockpluscore/test_runner.js
28 function webpackInMemory(options)
29 {
30 return new Promise((resolve, reject) =>
31 {
32 // Based on this example
33 // https://webpack.js.org/api/node/#custom-file-systems
34 let memoryFS = new MemoryFS();
35
36 let webpackCompiler = webpack(options);
37 webpackCompiler.outputFileSystem = memoryFS;
38
39 webpackCompiler.run((err, stats) =>
40 {
41 // Error handling is based on this example
42 // https://webpack.js.org/api/node/#error-handling
43 if (err)
44 {
45 let reason = err.stack || err;
46 if (err.details)
47 reason += "\n" + err.details;
48 reject(reason);
49 }
50 else if (stats.hasErrors())
51 reject(stats.toJson().errors.join("\n"));
52 else
53 {
54 let filepath = path.join(options.output.path, options.output.filename);
55 let bundle = memoryFS.readFileSync(filepath, "utf-8");
56 memoryFS.unlinkSync(filepath);
57 resolve([bundle, stats]);
58 }
59 });
60 });
61 }
62
63 // Since the cost of starting Node.js and loading all the modules is hugely
64 // larger than actually producing bundles we avoid paying it multiple times.
65 // To acheive this we output all the required bundles - along with their
66 // names - in one go.
67 for (let {BUNDLE_NAME, ENTRY_POINTS} of BUNDLES)
68 {
69 webpackInMemory({
70 context: EXTENSION_PATH,
71 devtool: "inline-source-map",
72 module: {
73 rules: [{
74 include: path.join(EXTENSION_PATH, "lib", "info.js"),
75 use: ["info-loader"]
76 }]
77 },
78 entry: ENTRY_POINTS,
79 output: {
80 path: "/",
81 filename: BUNDLE_NAME
82 },
83 resolve: {
84 modules: RESOLVE_PATHS,
85 alias: {
86 // Prevent builtin Node.js modules from being used instead of our own
87 // when the names clash. Once relative paths are used this won't be
88 // necessary.
89 url$: "url.js",
90 events$: "events.js",
91 punycode$: "punycode.js"
92 },
93 plugins: [
94 function()
95 {
96 // Our old module system in packagerChrome.py used to prefix
97 // module names with the name of their parent directory and an
98 // underscore - but only when that directory wasn't called
99 // "lib". This plugin is for backwards compatability, but can
100 // be removed once use of that deprecated syntax has been
101 // replaced.
102 this.plugin("described-resolve", (request, callback) =>
103 {
104 let target = request.request;
105
106 let prefix_index = target.indexOf("_");
107 if (prefix_index == -1)
108 return callback();
109
110 let prefix = target.substring(0, prefix_index);
111 if (prefix == "lib")
112 return callback();
113
114 let fixed_target = path.join(prefix,
115 target.substring(prefix_index + 1));
116 return this.doResolve(
117 "resolve", Object.assign({}, request, {request: fixed_target}),
118 "Changed prefixed path using legacy buildtools syntax from " +
119 target + " to " + fixed_target,
120 callback
121 );
122 });
123 }
124 ]
125 },
126 resolveLoader: {
127 modules: [path.resolve(__dirname)]
128 }
129 }).then(([bundle, stats]) =>
130 {
131 console.log(BUNDLE_NAME, BOUNDARY, bundle, BOUNDARY);
132 }).catch(e =>
133 {
134 console.error(e);
135 process.exit(1);
136 });
137 }
OLDNEW
« no previous file with comments | « webpack.config.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld