-
Notifications
You must be signed in to change notification settings - Fork 249
Add Hard source Webpack Plugin for perf improvement #646
Conversation
I forgot about the benchmark:
|
977bbf7
to
b7d42af
Compare
This sucks so much. We need to report this, it definitely looks like a bug of this plugin. |
Actually, this is my fault. HardSouceWebpackPlugin cache must be cleaned if the webpack config is changed. Our dev and static config is different so we'll need to use a different cache folder for dev and static |
@MoOx looks good to you? |
Appveyor hang at flow check step. Not relevant to this PR |
|
||
const chunkNameBrowser = "phenomic.browser" | ||
|
||
export default (config: PhenomicConfig): WebpackConfig => { | ||
// Use different cache folder for hard-source-webpack-plugin on each env | ||
const env = (config.production) ? "prod" : "dev" |
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.
You should use a hash on the entire config object. Other flag might change and be used too like "config.static" or some others (user custom flags?). We need to be sure that we will have one cache per POSSIBLE config :)
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.
Do you prefer any hash algorithm?
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.
You can just use something like that https://www.npmjs.com/package/node-object-hash
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.
Look like we are gonna store a lot of junk files in user's node modules folder.
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 we don't do that, we open ourselves to get a ton of issues for each people "specific use cases".
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.
I am pretty sure all efficient static gen have a lot of cache files.
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.
Fair point. Will store cach with hashed config object
Any news? |
@MoOx Will work on this soon. I'm trying to finish my client's website (phenomic based). IMHO, we don't need dll plugin once we have this. 20 secs for docs build is acceptable. |
dll plugins is definitely an important booster. 20s is too long. Go and ask Hugo users. :D |
dll plugins allows to only compile YOUR code (eg: compile a dependencies.dll.js with all npm deps, and only compile YOUR code in dev, which boost a LOT the build). |
I am using it at work and it's really nice, especially for a REALLY FAST hot loading. |
I am a Hugo user. Lol. With go, build time is calculated with milisecond, not second |
I know, that's why I said that. But hugo users don't have an assets graphs like webpack offers :) Anyway if we can reduce time, we will. |
I think we should ask Hard-source-webpack-plugin author's first before using DLL. If I'm not wrong hard source cache dependencies resolution too. And well, try this branch. reloading time is < 100ms |
Using dll is another step. dll is: you make a build of the deps you want, then you have a use dll.js + a manifest. Then for your other build, you consume the manifest. THis way webpack does not even have to compile the deps referenced. So I guess this is totally ok to use both projects. |
eca77dc
to
0c45225
Compare
@MoOx could you take a look ? |
const hasher = new ObjectHash() | ||
const hash = hasher.hash(config) | ||
|
||
const cacheDir = findCacheDir({ name: "phenomic-hard-source-wp/" + hash }) |
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.
we should put everything under "phenomic/*". So more "phenomic/hard-source-webpack/" + hash
. (wp is confusing)
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.
currently, there is no namespace in phenomic/*
. Perhaps I can move the old webpack static build cache to phenomic/webpack-static-build/*
?
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.
yep, but we can do that later, no big deal :)
This is still not working for node? Maybe:
Also we should be careful cause coverage is dropping down this days :) |
I can add more tests but looks at the diff, it's literally straight forward no logic to test :/ |
I guess people might trust more a project that have almost 100%. |
@MoOx PR updated. Good news: By setting cache based on config's hash. We can use hard-source on static build.
|
Wowww. That's a serious improvement! |
I was surprised too. Can't wait to use this . |
I saw you put this default to true. Should we set to false for a while (like if that's experimental?). I can't tell since I didn't used it on any project yet :) |
@MoOx mark this as an experimental feature. Set default to false |
Cool! Will merge in a moment! |
new HardSourceWebpackPlugin({ | ||
cacheDirectory: join(cacheDir, "cacheDirectory"), | ||
environmentPaths: { | ||
root: config.cwd, |
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.
@thangngoc89 why you didn't add "directory: [ "node_modules" ]" here?
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.
Because we use node_modules as cache directory. That will make hard-source clean cache everytime
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.
Hoooo shit. Good point. Maybe we should consider using a .phenomic folder for our cache then (if that can avoid issue)...
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.
Hum. How about os.tmpDir()
?
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.
yeah maybe. At the end I am not a fan of the cache in node_modules directory. We should investigate for existing solid solutions.
There are 2 things that concern me:
files
anddirectories
field must be config explicitly for each project. Checkout docs.If we move this to user's land, we might need to merge this PR: #642 for determine whether this is a node build or a browser one.
Just found a bug, put this in WIP mode:
If I perform a static build and then run the dev server after that, there will be a additional css file which is inserted to that page as a script tag, this broke the page.
So we need to clean cache between static and dev mode.