feat: library target UMD supports names per target - #4883
Conversation
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
sokra
left a comment
There was a problem hiding this comment.
A testcase in test/configCases would be great too to test the configuration schema
| }.bind(this)); | ||
| mainTemplate.plugin("global-hash-paths", function(paths) { | ||
| if(this.name) paths = paths.concat(this.name); | ||
| if(this.names.root) paths = paths.concat(this.names.root); |
There was a problem hiding this comment.
@sokra Is it okay if names are repeated in paths, or do we need to dedupe first?
There was a problem hiding this comment.
That's ok. They should just contribute all to the hash.
There was a problem hiding this comment.
@sokra Again here, the paths have been added for all names.
| mainTemplate.plugin("hash", function(hash) { | ||
| hash.update("umd"); | ||
| hash.update(`${this.name}`); | ||
| hash.update(`${this.names.root}`); |
| @@ -0,0 +1 @@ | |||
| original No newline at end of file | |||
There was a problem hiding this comment.
these files should not be commited (temp)
There was a problem hiding this comment.
@sokra Oops, thanks. Any reason not to add a pattern to .gitignore for these? As well as test/statsCases/*/actual.txt?
| if(typeof name === "object" && !Array.isArray(name)) { | ||
| this.name = name.root || name.amd || name.commonjs; | ||
| this.names = name; | ||
| } else { |
There was a problem hiding this comment.
does the schema allow an object as output.libraryName?
There was a problem hiding this comment.
@sokra Good point. Updated schema and added test.
| (this.name && this.namedDefine === true ? | ||
| " define(" + libraryName(this.name) + ", [], " + amdFactory + ");\n" : | ||
| (this.names.amd && this.namedDefine === true ? | ||
| " define(" + libraryName(this.names.amd) + ", [], " + amdFactory + ");\n" : |
There was a problem hiding this comment.
this line is not tested, if you want to you can add a test, but it's not required.
There was a problem hiding this comment.
@sokra Thanks, I've added tests for namedDefine being true and false. I'm not sure why it was a string value before, as I'm not sure that's a valid value per the docs - I'd only copied that from other test cases.
There was a problem hiding this comment.
@sokra Not sure how to get that line covered. Looks like it wasn't before either, and this PR now improves coverage overall. https://codecov.io/gh/webpack/webpack/pull/4883/changes
|
@AndersDJohnson Thanks for your update. I labeled the Pull Request so reviewers will review it again. @sokra Please review the new changes. |
5e8dcd6 to
d87fb0e
Compare
|
It looks like this Pull Request doesn't include enough test cases (based on Code Coverage analysis of the PR diff). A PR need to be covered by tests if you add a new feature (we want to make sure that your feature is working) or if you fix a bug (we want to make sure that we don't run into a regression in future). @AndersDJohnson Please check if this is appliable to your PR and if you can add more test cases. Read the test readme for details how to write test cases. |
| }.bind(this)); | ||
| mainTemplate.plugin("global-hash-paths", function(paths) { | ||
| if(this.name) paths = paths.concat(this.name); | ||
| if(this.names.root) paths = paths.concat(this.names.root); |
There was a problem hiding this comment.
That's ok. They should just contribute all to the hash.
| mainTemplate.plugin("hash", function(hash) { | ||
| hash.update("umd"); | ||
| hash.update(`${this.name}`); | ||
| hash.update(`${this.names.root}`); |
|
Could you sign the CLA, so we can merge it? |
|
@sokra CLA has been signed. |
|
@sokra Thanks for merging. |
What kind of change does this PR introduce?
feature
Did you add tests for your changes?
Yes, I updated the tests for
LibraryTemplatePlugin. There didn't seem to be any forUmdMainTemplatePluginyet - not sure if that's intentional, but if not, I could look into adding.If relevant, link to documentation update:
I'll take the time to add documentation after getting approval for this feature.
Summary
Currently, the
output.libraryTargetof'umd'only supports a single name (output.library), whereas the user may instead wish to specify a different name for each target type (CommonJS, AMD, and global), e.g., to use kebab-case for AMD and CommonJS but camelCase for global.Does this PR introduce a breaking change?
No.
Other information
Feel free to ask.