-
Notifications
You must be signed in to change notification settings - Fork 12k
feat(build): allow output hashing to be configured #3885
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
|
||
export const getWebpackDevConfigPartial = function(projectRoot: string, appConfig: any) { | ||
return { | ||
output: { | ||
filename: '[name].bundle.js', | ||
sourceMapFilename: '[name].bundle.map', | ||
chunkFilename: '[id].chunk.js' | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin({filename: '[name].bundle.css'}) | ||
] | ||
}; | ||
return { }; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {stripIndents} from 'common-tags'; | ||
import * as fs from 'fs'; | ||
import {ng} from '../../utils/process'; | ||
import { writeMultipleFiles, expectFileToMatch } from '../../utils/fs'; | ||
|
||
function verifyMedia(css: RegExp, content: RegExp) { | ||
return new Promise((resolve, reject) => { | ||
const [fileName] = fs.readdirSync('./dist').filter(name => name.match(css)); | ||
if (!fileName) { | ||
reject(new Error(`File ${fileName} was expected to exist but not found...`)); | ||
} | ||
resolve(fileName); | ||
}) | ||
.then(fileName => expectFileToMatch(`dist/${fileName}`, content)); | ||
} | ||
|
||
export default function() { | ||
return Promise.resolve() | ||
.then(() => writeMultipleFiles({ | ||
'src/styles.css': stripIndents` | ||
body { background-image: url("image.svg"); } | ||
`, | ||
'src/image.svg': 'I would like to be an image someday.' | ||
})) | ||
.then(() => ng('build', '--dev', '--output-hashing=all')) | ||
.then(() => expectFileToMatch('dist/index.html', /inline\.[0-9a-f]{20}\.bundle\.js/)) | ||
.then(() => expectFileToMatch('dist/index.html', /main\.[0-9a-f]{20}\.bundle\.js/)) | ||
.then(() => expectFileToMatch('dist/index.html', /styles\.[0-9a-f]{20}\.bundle\.(css|js)/)) | ||
.then(() => verifyMedia(/styles\.[0-9a-f]{20}\.bundle\.(css|js)/, /image\.[0-9a-f]{20}\.svg/)) | ||
|
||
.then(() => ng('build', '--prod', '--output-hashing=none')) | ||
.then(() => expectFileToMatch('dist/index.html', /inline\.bundle\.js/)) | ||
.then(() => expectFileToMatch('dist/index.html', /main\.bundle\.js/)) | ||
.then(() => expectFileToMatch('dist/index.html', /styles\.bundle\.(css|js)/)) | ||
.then(() => verifyMedia(/styles\.bundle\.(css|js)/, /image\.svg/)) | ||
|
||
.then(() => ng('build', '--dev', '--output-hashing=media')) | ||
.then(() => expectFileToMatch('dist/index.html', /inline\.bundle\.js/)) | ||
.then(() => expectFileToMatch('dist/index.html', /main\.bundle\.js/)) | ||
.then(() => expectFileToMatch('dist/index.html', /styles\.bundle\.(css|js)/)) | ||
.then(() => verifyMedia(/styles\.bundle\.(css|js)/, /image\.[0-9a-f]{20}\.svg/)) | ||
|
||
.then(() => ng('build', '--dev', '--output-hashing=bundles')) | ||
.then(() => expectFileToMatch('dist/index.html', /inline\.[0-9a-f]{20}\.bundle\.js/)) | ||
.then(() => expectFileToMatch('dist/index.html', /main\.[0-9a-f]{20}\.bundle\.js/)) | ||
.then(() => expectFileToMatch('dist/index.html', /styles\.[0-9a-f]{20}\.bundle\.(css|js)/)) | ||
.then(() => verifyMedia(/styles\.[0-9a-f]{20}\.bundle\.(css|js)/, /image\.svg/)); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Gotta say I love the fact that this change makes the dev config dispensable. Can you remove it from the webpack merge procedure as well?
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 was planning on making a PR that adds
NamedModulesPlugin
to dev builds to support HMR. Can do it another way though (e.g., only when HMR is enabled), if you'd prefer the file removed.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 there's a reason for the file to exist then it shouldn't be removed. I didn't know of
NamedModulesPlugin
but a quick google search made me think it's main use is to have good names in HMR, is that correct? If so, it makes sense to have it automatically with HMR, yes.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's the reason I was going to add it. But it also stabilizes the module id's between builds which has benefits for cache busting. The hash won't change due to webpack module id renumbering. Nothing bad happens without it; the hash just might change more often than needed. And this isn't really relevant for HMR and probably not for dev builds in general.
For production builds there is
HashedModuleIdsPlugin
, which hashes the names to obfuscate the file path details.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'd be interested in such a PR then. Ping me if you end up doing it and I will review it.
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.
Also wonder if that would help with the reload times tbh. It sounds like it might do away with rebuilding some modules due to id changes.
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.
Not sure. But I'll see if I can put a PR together.
Also, I was looking through
webpack-config.ts
where the merging happens and to cleanly remove the dev config will require some refactoring (which the file could probably use either way) so it might be best to leave it for a followup PR.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 want to refactor the way we pass options down to the webpack config anyway, so I can do that at the time. It's getting messy as is.