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: Tidy up JSON passed from packagerChrome.py Created Oct. 4, 2017, 1:23 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
« 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 58%
rename from webpack.config.js
rename to webpack_runner.js
index 3e061af1b2a4a25c60a261bd31ba91db127f05f5..533b15ad4bf39fe6067cb15659083d9ff0f67fec 100644
--- a/webpack.config.js
+++ b/webpack_runner.js
@@ -16,22 +16,67 @@
*/
const path = require("path");
+const process = require("process");
-let {EXTENSION_PATH, ENTRY_POINTS, OUTPUT_PATH, BUNDLE_NAME,
- RESOLVE_PATHS, INFO_PATH} = require("process").env;
+const MemoryFS = require("memory-fs");
+const webpack = require("webpack");
-module.exports = {
+let {BUNDLE_NAME, ENTRY_POINTS, EXTENSION_PATH,
+ RESOLVE_PATHS} = JSON.parse(process.argv[2]);
+
+// Copied from adblockpluscore/test_runner.js
+function webpackInMemory(options)
+{
+ return new Promise((resolve, reject) =>
+ {
+ // Based on this example
+ // https://webpack.js.org/api/node/#custom-file-systems
+ let memoryFS = new MemoryFS();
+
+ 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.join("\n"));
+ else
+ {
+ let filepath = path.join(options.output.path, options.output.filename);
+ let bundle = memoryFS.readFileSync(filepath, "utf-8");
+ memoryFS.unlinkSync(filepath);
+ resolve([bundle, stats]);
+ }
+ });
+ });
+}
+
+webpackInMemory({
context: EXTENSION_PATH,
- devtool: "source-map",
- entry: ENTRY_POINTS.split(" "),
+ devtool: "inline-source-map",
+ module: {
+ rules: [{
+ include: path.join(EXTENSION_PATH, "lib", "info.js"),
+ use: ["info-loader"]
+ }]
+ },
+ entry: ENTRY_POINTS,
output: {
- path: OUTPUT_PATH,
+ path: "/",
filename: BUNDLE_NAME
},
resolve: {
- modules: RESOLVE_PATHS.split(" "),
+ modules: RESOLVE_PATHS,
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,14 @@ 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);
+}).catch(e =>
+{
+ 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