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
feat: library target UMD supports names per target #4883
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. |
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.
A testcase in test/configCases would be great too to test the configuration schema
@@ -163,12 +173,12 @@ class UmdMainTemplatePlugin { | |||
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})"); | |||
}.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add all names 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.
@sokra Is it okay if names are repeated in paths
, or do we need to dedupe first?
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 ok. They should just contribute all to the 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.
@sokra Again here, the paths have been added for all names.
return paths; | ||
}.bind(this)); | ||
mainTemplate.plugin("hash", function(hash) { | ||
hash.update("umd"); | ||
hash.update(`${this.name}`); | ||
hash.update(`${this.names.root}`); |
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.
here also all names
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.
@sokra Again, is it okay if names are repeated here, or do we need to dedupe first?
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, it's ok
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.
@sokra The hash has been updated with all names.
test/fixtures/temp-1000/file2.js
Outdated
@@ -0,0 +1 @@ | |||
original |
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.
these files should not be commited (temp)
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the schema allow an object as output.libraryName
?
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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. |
@@ -163,12 +173,12 @@ class UmdMainTemplatePlugin { | |||
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})"); | |||
}.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's ok. They should just contribute all to the hash.
return paths; | ||
}.bind(this)); | ||
mainTemplate.plugin("hash", function(hash) { | ||
hash.update("umd"); | ||
hash.update(`${this.name}`); | ||
hash.update(`${this.names.root}`); |
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, it's ok
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 forUmdMainTemplatePlugin
yet - 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.libraryTarget
of'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.