Skip to content

Commit 32e7ba6

Browse files
refactor: esModule is set to true by default (#344)
BREAKING CHANGE: the `esModule` option is `true` by default, it means we generate `import ... from ...` for sources instead `require`
1 parent eeb284c commit 32e7ba6

File tree

7 files changed

+355
-355
lines changed

7 files changed

+355
-355
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports = {
5555
| **[`attributes`](#attributes)** | `{Boolean\|Object}` | `true` | Enables/Disables attributes handling |
5656
| **[`preprocessor`](#preprocessor)** | `{Function}` | `undefined` | Allows pre-processing of content before handling |
5757
| **[`minimize`](#minimize)** | `{Boolean\|Object}` | `true` in production mode, otherwise `false` | Tell `html-loader` to minimize HTML |
58-
| **[`esModule`](#esmodule)** | `{Boolean}` | `false` | Use ES modules syntax |
58+
| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Enable/disable ES modules syntax |
5959

6060
### `attributes`
6161

@@ -488,12 +488,12 @@ module.exports = {
488488
### `esModule`
489489

490490
Type: `Boolean`
491-
Default: `false`
491+
Default: `true`
492492

493-
By default, `html-loader` generates JS modules that use the CommonJS modules syntax.
493+
By default, `html-loader` generates JS modules that use the ES modules syntax.
494494
There are some cases in which using ES modules is beneficial, like in the case of [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).
495495

496-
You can enable a ES module syntax using:
496+
You can enable a CommonJS modules syntax using:
497497

498498
**webpack.config.js**
499499

@@ -505,7 +505,7 @@ module.exports = {
505505
test: /\.html$/i,
506506
loader: 'html-loader',
507507
options: {
508-
esModule: true,
508+
esModule: false,
509509
},
510510
},
511511
],

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ export function normalizeOptions(rawOptions, loaderContext) {
781781
attributes: getAttributesOption(rawOptions),
782782
minimize: getMinimizeOption(rawOptions, loaderContext),
783783
esModule:
784-
typeof rawOptions.esModule === 'undefined' ? false : rawOptions.esModule,
784+
typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule,
785785
};
786786
}
787787

test/__snapshots__/attributes-option.test.js.snap

Lines changed: 135 additions & 135 deletions
Large diffs are not rendered by default.

test/__snapshots__/esModule-option.test.js.snap

Lines changed: 23 additions & 23 deletions
Large diffs are not rendered by default.

test/__snapshots__/loader.test.js.snap

Lines changed: 35 additions & 35 deletions
Large diffs are not rendered by default.

test/__snapshots__/minimize-option.test.js.snap

Lines changed: 142 additions & 142 deletions
Large diffs are not rendered by default.

test/__snapshots__/preprocessor-option.test.js.snap

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ exports[`'process' option should work with Async "preprocessor" Function option:
44

55
exports[`'process' option should work with Async "preprocessor" Function option: module 1`] = `
66
"// Imports
7-
var ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ = require(\\"../../src/runtime/getUrl.js\\");
8-
var ___HTML_LOADER_IMPORT_0___ = require(\\"./image.png\\");
7+
import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\";
8+
import ___HTML_LOADER_IMPORT_0___ from \\"./image.png\\";
99
// Module
1010
var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
1111
var code = \\"<div>\\\\n <p>Alexander Krasnoyarov</p>\\\\n <img src=\\\\\\"\\" + ___HTML_LOADER_REPLACEMENT_0___ + \\"\\\\\\" alt=\\\\\\"alt\\\\\\" />\\\\n<div>\\\\n\\";
1212
// Exports
13-
module.exports = code;"
13+
export default code;"
1414
`;
1515
1616
exports[`'process' option should work with Async "preprocessor" Function option: result 1`] = `
@@ -27,15 +27,15 @@ exports[`'process' option should work with the "preprocessor" option #2: errors
2727
2828
exports[`'process' option should work with the "preprocessor" option #2: module 1`] = `
2929
"// Imports
30-
var ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ = require(\\"../../src/runtime/getUrl.js\\");
31-
var ___HTML_LOADER_IMPORT_0___ = require(\\"./image.png.webp\\");
32-
var ___HTML_LOADER_IMPORT_1___ = require(\\"./image.png\\");
30+
import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\";
31+
import ___HTML_LOADER_IMPORT_0___ from \\"./image.png.webp\\";
32+
import ___HTML_LOADER_IMPORT_1___ from \\"./image.png\\";
3333
// Module
3434
var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
3535
var ___HTML_LOADER_REPLACEMENT_1___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_1___);
3636
var code = \\"<picture><source type=\\\\\\"image/webp\\\\\\" srcset=\\\\\\"\\" + ___HTML_LOADER_REPLACEMENT_0___ + \\"\\\\\\"><img src=\\\\\\"\\" + ___HTML_LOADER_REPLACEMENT_1___ + \\"\\\\\\"></picture>\\\\n\\";
3737
// Exports
38-
module.exports = code;"
38+
export default code;"
3939
`;
4040
4141
exports[`'process' option should work with the "preprocessor" option #2: result 1`] = `
@@ -49,13 +49,13 @@ exports[`'process' option should work with the "preprocessor" option: errors 1`]
4949
5050
exports[`'process' option should work with the "preprocessor" option: module 1`] = `
5151
"// Imports
52-
var ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ = require(\\"../../src/runtime/getUrl.js\\");
53-
var ___HTML_LOADER_IMPORT_0___ = require(\\"./image.png\\");
52+
import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\";
53+
import ___HTML_LOADER_IMPORT_0___ from \\"./image.png\\";
5454
// Module
5555
var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
5656
var code = \\"<div>\\\\n <p>Alexander Krasnoyarov</p>\\\\n <img src=\\\\\\"\\" + ___HTML_LOADER_REPLACEMENT_0___ + \\"\\\\\\" alt=\\\\\\"alt\\\\\\" />\\\\n<div>\\\\n\\";
5757
// Exports
58-
module.exports = code;"
58+
export default code;"
5959
`;
6060
6161
exports[`'process' option should work with the "preprocessor" option: result 1`] = `
@@ -72,15 +72,15 @@ exports[`'process' option should work with the Async "preprocessor" Function opt
7272
7373
exports[`'process' option should work with the Async "preprocessor" Function option #2: module 1`] = `
7474
"// Imports
75-
var ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ = require(\\"../../src/runtime/getUrl.js\\");
76-
var ___HTML_LOADER_IMPORT_0___ = require(\\"./image.png.webp\\");
77-
var ___HTML_LOADER_IMPORT_1___ = require(\\"./image.png\\");
75+
import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\";
76+
import ___HTML_LOADER_IMPORT_0___ from \\"./image.png.webp\\";
77+
import ___HTML_LOADER_IMPORT_1___ from \\"./image.png\\";
7878
// Module
7979
var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
8080
var ___HTML_LOADER_REPLACEMENT_1___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_1___);
8181
var code = \\"<picture><source type=\\\\\\"image/webp\\\\\\" srcset=\\\\\\"\\" + ___HTML_LOADER_REPLACEMENT_0___ + \\"\\\\\\"><img src=\\\\\\"\\" + ___HTML_LOADER_REPLACEMENT_1___ + \\"\\\\\\"></picture>\\\\n\\";
8282
// Exports
83-
module.exports = code;"
83+
export default code;"
8484
`;
8585
8686
exports[`'process' option should work with the Async "preprocessor" Function option #2: result 1`] = `

0 commit comments

Comments
 (0)