Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Add support for dynamic filenames #83

Merged
merged 3 commits into from Dec 18, 2019

Conversation

jimmydief
Copy link
Contributor

Add support for a custom filename template for worker scripts through use of Webpack's loader-utils. This allows worker files to be served with long-lived caching headers through the use of content hashes. It also allows for files to be generated into particular directories through use of a template like js/[name].worker.js.

Like #81, not sure what the automated testing strategy should be.

Fixes #29.

@msftclas
Copy link

msftclas commented Nov 21, 2019

CLA assistant check
All CLA requirements met.

@@ -9,18 +12,29 @@ const EDITOR_MODULE = {
worker: {
id: 'vs/editor/editor',
entry: 'vs/editor/editor.worker',
output: 'editor.worker.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer required as the [name] attribute used to resolve the filename template is based on the entry filename. All generated files have the same names as before unless filename is specified.

*/
function getWorkerFilename(filename, entry) {
return loaderUtils.interpolateName({resourcePath: entry}, filename, {
content: fs.readFileSync(resolveMonacoPath(entry))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using loader-utils so that the full breadth of Webpack filename options is supported. We read the entry file from the file system so that content-based hashes will update based on worker file contents.

Add support for custom filename template for worker scripts.
* custom output path for worker scripts, relative to the main webpack `output.path`.
* Defaults to ''.
*/
output?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new option subsumes the old output option since filenames can include directories through use of a slash.

package.json Outdated
@@ -35,6 +35,7 @@
"webpack-cli": "^3.1.2"
},
"dependencies": {
"@types/webpack": "^4.4.19"
"@types/webpack": "^4.4.19",
"loader-utils": "^1.2.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already included in #74 but adding this here to pin the version so that [contenthash] is available when testing.

@alexdima
Copy link
Member

Thank you! ❤️

@alexdima alexdima added this to the December 2019 milestone Dec 18, 2019
@alexdima alexdima merged commit e032f77 into microsoft:master Dec 18, 2019
@jimmydief jimmydief deleted the dynamic_filenames branch January 29, 2020 08:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The generated worker files should support chunkhash
3 participants