diff --git a/package.json b/package.json index b01d9e2c..7fe915f6 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "typescript": "^3.2.2", "vue": "^2.5.17", "vue-server-renderer": "^2.5.17", - "webpack": "github:webpack/webpack#next", + "webpack": "5.0.0-alpha.0", "when": "^3.7.8" } } diff --git a/src/index.js b/src/index.js index d0e0517f..09b6eb63 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ const resolve = require("resolve"); const fs = require("graceful-fs"); +const crypto = require("crypto"); const { sep } = require("path"); const webpack = require("webpack"); const MemoryFS = require("memory-fs"); @@ -15,6 +16,14 @@ const nodeBuiltins = new Set([...require("repl")._builtinLibs, "constants", "mod const SUPPORTED_EXTENSIONS = [".js", ".json", ".node", ".mjs", ".ts", ".tsx"]; +const hashOf = name => { + return crypto + .createHash("md4") + .update(name) + .digest("hex") + .slice(0, 10); +} + module.exports = ( entry, { @@ -53,9 +62,8 @@ module.exports = ( cache: cache === false ? undefined : { type: "filesystem", cacheDirectory: typeof cache === 'string' ? cache : nccCacheDir, - name: "ncc", - version: require('../package.json').version, - store: "instant" + name: `ncc_${hashOf(entry)}`, + version: require('../package.json').version }, optimization: { nodeEnv: false, @@ -78,7 +86,7 @@ module.exports = ( }, // https://github.com/zeit/ncc/pull/29#pullrequestreview-177152175 node: false, - externals: async (context, request, callback) => { + externals: async ({ context, request }, callback) => { if (externalSet.has(request)) return callback(null, `commonjs ${request}`); if (request[0] === "." && (request[1] === "/" || request[1] === "." && request[2] === "/")) { if (request.startsWith("./node_modules/")) request = request.substr(15); @@ -208,9 +216,10 @@ module.exports = ( return new Promise((resolve, reject) => { compiler.run((err, stats) => { if (err) return reject(err); - if (stats.hasErrors()) - return reject(new Error(stats.toString())); - compiler.close(() => { + compiler.close(err => { + if (err) return reject(err); + if (stats.hasErrors()) + return reject(new Error(stats.toString())); resolve(); }); }); diff --git a/yarn.lock b/yarn.lock index 9d46f5a8..d9e6bba3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11109,9 +11109,10 @@ webpack-sources@^1.1.0, webpack-sources@^1.3.0: source-list-map "^2.0.0" source-map "~0.6.1" -"webpack@github:webpack/webpack#next": - version "5.0.0-next" - resolved "https://codeload.github.com/webpack/webpack/tar.gz/3f71a165bf17bfb27138dcba799d9437a9af558c" +webpack@5.0.0-alpha.0: + version "5.0.0-alpha.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.0.0-alpha.0.tgz#6fdd442932ff232da783e629f2ffcf29a571b533" + integrity sha512-dycVcffNaebFKI5Y6yv4yvtzAqr6MahHMBo58I9+YZQUAlf8x7sjVwFbCzxtEKLR3DAihJeQ7RscpqEQqimpuQ== dependencies: "@webassemblyjs/ast" "1.7.11" "@webassemblyjs/helper-module-context" "1.7.11"