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
Add assetExtname replacement in entryFileNames #4077
Conversation
This only has an effect when preserveModules is enaled. This allows consumers who want to customise the entry file name to easily implement the "only add an extension for non js/ts files" logic that rollup does if you don't specify entryFileNames.
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install BPScott/rollup#asset-extname or load it into the REPL: |
Question: I couldn't see any prior art for how to name multi-word replacements so I went with camel case for |
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.
Looks good, makes sense to me. Bonus points for updating the documentation. Will need to wait for GitHub Actions to work properly again before merging, though.
Codecov Report
@@ Coverage Diff @@
## master #4077 +/- ##
=======================================
Coverage 97.49% 97.49%
=======================================
Files 193 193
Lines 6824 6824
Branches 2006 2005 -1
=======================================
Hits 6653 6653
Misses 84 84
Partials 87 87
Continue to review full report at Codecov.
|
Pushed a change to fix the linting error |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers: #3107 #3116
Description
When using
preserveModules
by default rollup adds the original extension of non-js/ts files to the generated filename. E.g.foo.txt
compiles tofoo.txt.js
(so that it doesn't clash withfoo.js
). This behaviour was added in #3116. This is great, however it is a little tricky to emulate when customising the output filename withentryFileNames
.If I wanted the same-as-default behaviour but outputting
.mjs
extensions I could pass a function to entryFilenames but it is pretty dang clunky:Instead I would like to propose adding an
assetExtname
replacement, that returns the extension prefixed with a.
(same as extname) if the extension is not one of the "non asset extensions".With this change, having rollup's default behaviour but outputting
.mjs
filenames can be done by setting entryFilenames to'[name][assetExtname].mjs'
.