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

Unified Diff: webpack_runner.js

Issue 29549786: Issue 5535 - Replace our module system with webpack (Closed)
Patch Set: Avoid writing files when producing webpack bundles Created Oct. 2, 2017, 6:38 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« package.json ('K') | « webpack.config.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webpack_runner.js
diff --git a/webpack.config.js b/webpack_runner.js
similarity index 58%
rename from webpack.config.js
rename to webpack_runner.js
index 3e061af1b2a4a25c60a261bd31ba91db127f05f5..87fe97b929554a1e52d1bc69e664a2f1d2e49ffc 100644
--- a/webpack.config.js
+++ b/webpack_runner.js
@@ -16,14 +16,60 @@
*/
const path = require("path");
+const process = require("process");
+
+const MemoryFS = require("memory-fs");
+const webpack = require("webpack");
let {EXTENSION_PATH, ENTRY_POINTS, OUTPUT_PATH, BUNDLE_NAME,
- RESOLVE_PATHS, INFO_PATH} = require("process").env;
+ RESOLVE_PATHS} = require("process").env;
+
+// Copied from adblockpluscore/test_runner.js
+function webpackInMemory(bundleFilename, options)
+{
+ return new Promise((resolve, reject) =>
+ {
+ // Based on this example
+ // https://webpack.js.org/api/node/#custom-file-systems
+ let memoryFS = new MemoryFS();
+
+ options.output = {filename: bundleFilename, path: "/"};
+ let webpackCompiler = webpack(options);
+ webpackCompiler.outputFileSystem = memoryFS;
+
+ webpackCompiler.run((err, stats) =>
+ {
+ // Error handling is based on this example
+ // https://webpack.js.org/api/node/#error-handling
+ if (err)
+ {
+ let reason = err.stack || err;
+ if (err.details)
+ reason += "\n" + err.details;
+ reject(reason);
+ }
+ else if (stats.hasErrors())
+ reject(stats.toJson().errors);
+ else
+ {
+ let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8");
+ memoryFS.unlinkSync("/" + bundleFilename);
+ resolve(bundle);
+ }
+ });
+ });
+}
-module.exports = {
+webpackInMemory(BUNDLE_NAME, {
context: EXTENSION_PATH,
- devtool: "source-map",
+ devtool: "inline-source-map",
entry: ENTRY_POINTS.split(" "),
+ module: {
+ rules: [{
+ test: /info.js$/,
+ use: ["info-loader"]
+ }]
+ },
output: {
path: OUTPUT_PATH,
filename: BUNDLE_NAME
@@ -31,7 +77,6 @@ module.exports = {
resolve: {
modules: RESOLVE_PATHS.split(" "),
alias: {
- info$: INFO_PATH,
// Prevent builtin Node.js modules from being used instead of our own when
// the names clash. Once relative paths are used this won't be necessary.
url$: "url.js",
@@ -71,6 +116,9 @@ module.exports = {
}
]
},
+ resolveLoader: {
+ modules: [path.resolve(__dirname)]
+ },
stats: {
assets: false,
children: false,
@@ -86,4 +134,14 @@ module.exports = {
version: false,
warnings: true
}
-};
+}).then(console.log, e =>
+{
+ // I would prefer to simply leave the exception unhandled, since we want the
+ // script to end in that case. Unfortunatley though Node.js displays a
+ // deprecation warning if we do:
+ // "[DEP0018] DeprecationWarning: Unhandled promise rejections are
+ // deprecated. In the future, promise rejections that are not handled
+ // will terminate the Node.js process with a non-zero exit code."
+ console.error(e.join("\n"));
+ process.exit(1);
+});
« package.json ('K') | « webpack.config.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld