ESM: Config scripts now run synchronously before webpack builds start

This commit is contained in:
n1474335 2018-04-11 17:58:40 +00:00
parent 23f69bd21d
commit 4e38b09e18
5 changed files with 35 additions and 37 deletions

15
package-lock.json generated
View file

@ -12652,12 +12652,6 @@
"integrity": "sha1-Iyxi7GCSsQBjWj0p2DwXRxKN+b0=", "integrity": "sha1-Iyxi7GCSsQBjWj0p2DwXRxKN+b0=",
"dev": true "dev": true
}, },
"webpack-shell-plugin": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/webpack-shell-plugin/-/webpack-shell-plugin-0.5.0.tgz",
"integrity": "sha1-Kbih2A3erg3bEOcpZn9yhlPCx0I=",
"dev": true
},
"webpack-sources": { "webpack-sources": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.0.1.tgz", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.0.1.tgz",
@ -12668,6 +12662,15 @@
"source-map": "0.5.7" "source-map": "0.5.7"
} }
}, },
"webpack-synchronizable-shell-plugin": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/webpack-synchronizable-shell-plugin/-/webpack-synchronizable-shell-plugin-0.0.7.tgz",
"integrity": "sha512-b1ZPHwkHR5+MDRLp9CbLxDaaTTcf4/tmxU+Tc6Z3lpv6krnIPv0doXfgBHkDthHUkwsURyO9fgRnJ/VxyFBEwQ==",
"dev": true,
"requires": {
"babel-polyfill": "6.26.0"
}
},
"websocket-driver": { "websocket-driver": {
"version": "0.7.0", "version": "0.7.0",
"resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.0.tgz", "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.0.tgz",

View file

@ -63,7 +63,7 @@
"webpack": "^4.0.1", "webpack": "^4.0.1",
"webpack-dev-server": "^3.1.0", "webpack-dev-server": "^3.1.0",
"webpack-node-externals": "^1.6.0", "webpack-node-externals": "^1.6.0",
"webpack-shell-plugin": "^0.5.0", "webpack-synchronizable-shell-plugin": "0.0.7",
"worker-loader": "^1.1.1" "worker-loader": "^1.1.1"
}, },
"dependencies": { "dependencies": {

View file

@ -52,21 +52,20 @@ for (const opObj in Ops) {
/** /**
* Write OperationConfig. * Write OperationConfig.
*/ */
fs.writeFile( fs.writeFileSync(
path.join(dir, "OperationConfig.json"), path.join(dir, "OperationConfig.json"),
JSON.stringify(operationConfig, null, 4), JSON.stringify(operationConfig, null, 4)
err => {
if (err) {
console.error(err);
process.exit(1);
}
}
); );
console.log("Written OperationConfig.json");
/** /**
* Write modules. * Write modules.
*/ */
if (!fs.existsSync(path.join(dir, "modules/"))) {
fs.mkdirSync(path.join(dir, "modules/"));
}
for (const module in modules) { for (const module in modules) {
let code = `/** let code = `/**
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateConfig.mjs * THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateConfig.mjs
@ -96,16 +95,11 @@ OpModules.${module} = {
export default OpModules; export default OpModules;
`; `;
fs.writeFile( fs.writeFileSync(
path.join(dir, `modules/${module}.mjs`), path.join(dir, `modules/${module}.mjs`),
code, code
err => {
if (err) {
console.error(err);
process.exit(1);
}
}
); );
console.log(`Written ${module} module`);
} }
@ -143,16 +137,11 @@ opModulesCode += `);
export default OpModules; export default OpModules;
`; `;
fs.writeFile( fs.writeFileSync(
path.join(dir, "modules/OpModules.mjs"), path.join(dir, "modules/OpModules.mjs"),
opModulesCode, opModulesCode
err => {
if (err) {
console.error(err);
process.exit(1);
}
}
); );
console.log("Written OpModules.mjs");
/*"Fork": { /*"Fork": {

View file

@ -57,3 +57,4 @@ fs.writeFileSync(
path.join(dir, "../operations/index.mjs"), path.join(dir, "../operations/index.mjs"),
code code
); );
console.log("Written operation index.");

View file

@ -1,6 +1,6 @@
const webpack = require("webpack"); const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin"); const ExtractTextPlugin = require("extract-text-webpack-plugin");
const WebpackShellPlugin = require("webpack-shell-plugin"); const WebpackSyncShellPlugin = require("webpack-synchronizable-shell-plugin");
/** /**
* Webpack configuration details for use with Grunt. * Webpack configuration details for use with Grunt.
@ -44,11 +44,16 @@ module.exports = {
entryOnly: true entryOnly: true
}), }),
new ExtractTextPlugin("styles.css"), new ExtractTextPlugin("styles.css"),
new WebpackShellPlugin({ new WebpackSyncShellPlugin({
onBuildStart: [ onBuildStart: {
"node --experimental-modules src/core/config/scripts/generateOpsIndex.mjs", scripts: [
"node --experimental-modules src/core/config/scripts/generateConfig.mjs", "node --experimental-modules src/core/config/scripts/generateOpsIndex.mjs",
], "node --experimental-modules src/core/config/scripts/generateConfig.mjs",
"echo ---\nConfig scripts finished.\n---\n"
],
blocking: true,
parallel: false
}
}) })
], ],
resolve: { resolve: {