Skip to content

Commit 346d4a0

Browse files
committed
Use ESM exports in copy-files-loader for better webpack optimizations
1 parent f5bcccc commit 346d4a0

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ can adopt modern async APIs from the ecosystem without hacks**.
121121

122122
- Update postcss-loader support from 8.1.0 to 8.1.1 for ESM compatibility
123123
- Add support for [webpack-cli@7.0.0](https://github.com/webpack/webpack-cli/releases/tag/webpack-cli%407.0.0)
124+
- `Encore.copyFiles()` now internally generates ESM exports for better webpack optimizations (scope hoisting, module concatenation)
124125

125126
## 6.0.0
126127

lib/webpack/copy-files-loader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function interpolateName(template, { resourcePath, context, contentHash }) {
5858
* and customizing output paths using template placeholders.
5959
*
6060
* @param {Buffer} source - The raw file content
61-
* @returns {string} A CommonJS module that exports the public URL of the copied file
61+
* @returns {string} An ESM module that exports the public URL of the copied file
6262
*/
6363
export default function loader(source) {
6464
const options = this.getOptions();
@@ -82,7 +82,7 @@ export default function loader(source) {
8282
// "resolve.extensions" parameter of Webpack (for instance
8383
// if "./test.js" was matched by "./test").
8484
if (!pattern.test(relativeResourcePath)) {
85-
return 'module.exports = "";';
85+
return 'export default "";';
8686
}
8787

8888
// Compute content hash using webpack's built-in hashing utilities
@@ -112,5 +112,5 @@ export default function loader(source) {
112112
this.emitFile(outputPath, source, null, assetInfo);
113113

114114
// Return a module that exports the public URL
115-
return `module.exports = __webpack_public_path__ + ${JSON.stringify(outputPath)};`;
115+
return `export default __webpack_public_path__ + ${JSON.stringify(outputPath)};`;
116116
}

0 commit comments

Comments
 (0)