-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update webpack + pack mode #189
Changes from all commits
e775187
eea3f16
33ddfde
d88af64
6a67ea6
ae23f75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"); | ||
|
@@ -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)}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this not be a hash of the project directory, so that if the input changes the cache can still be used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've thought about that, but decided against it. This could be a problem when using This configuration provides consistent fast rebuilds at the cost of high initial build for each entry. But choosing the other way is also a valid trade-off. I assumed |
||
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(); | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If switching to the
pack
mode, should we also now ensure that the cache is a per-project cache in the node_modules folder instead of the single global cache?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make sense.
Another option is to keep the cache location, but use a different
cache.name
for each directory.Like this:
name: hashOf(directory)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The risk with the global cache with this new storage seems to be disk usage growth right?
I guess this can be mitigated with a simple eviction strategy in due course. But that was another argument for per-project caching.
The argument for global caching is that ideally it would be great if the global cache could be smart enough to know the hashes of the dependencies (yarn.lock again!), and thus share compilations.
Not sure which of the above you want to shoot for here, but will trust your judgement!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The per-project cache is garbage-collected, so disk usage should increase only with the number of different entries used on a computer.