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: Improve output on error Created Oct. 4, 2017, 10:28 a.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
« no previous file with comments | « 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 55%
rename from webpack.config.js
rename to webpack_runner.js
index 3e061af1b2a4a25c60a261bd31ba91db127f05f5..34cc11eaa17232497eb3bf09c914780dfa56a065 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;
-module.exports = {
+ 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.join("\n"));
+ else
+ {
+ let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8");
+ memoryFS.unlinkSync("/" + bundleFilename);
+ resolve([bundle, stats]);
+ }
+ });
+ });
+}
+
+webpackInMemory(BUNDLE_NAME, {
context: EXTENSION_PATH,
- devtool: "source-map",
+ devtool: "inline-source-map",
entry: ENTRY_POINTS.split(" "),
+ module: {
+ rules: [{
+ include: path.join(EXTENSION_PATH, "lib", "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,19 +116,23 @@ module.exports = {
}
]
},
- stats: {
- assets: false,
- children: false,
- chunks: false,
- errorDetails: true,
- errors: true,
- hash: false,
- modules: false,
- publicPath: false,
- reasons: false,
- source: false,
- timings: false,
- version: false,
- warnings: true
+ resolveLoader: {
+ modules: [path.resolve(__dirname)]
+ }
+}).then(
+ ([bundle, stats]) =>
+ {
+ console.log(bundle);
+ },
+ 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);
+ process.exit(1);
}
-};
+);
« 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