Skip to content

Commit

Permalink
Update webpack + pack mode (#189)
Browse files Browse the repository at this point in the history
* update webpack

* close compiler correctly even in case of errors

this makes sure that idle tasks are completed (like persisting cache)

* Use faster single file cache mode

* update to new externals signature

* create a cache per input file

* Use released webpack version from npm instead
  • Loading branch information
sokra authored and rauchg committed Dec 21, 2018
1 parent 373f5f1 commit fc3ecef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
23 changes: 16 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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,
{
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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();
});
});
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
[email protected]:
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"
Expand Down

0 comments on commit fc3ecef

Please sign in to comment.