Skip to content

Commit 727a24d

Browse files
feat: enabled esModule by default (#489)
BRAKING CHANGE: the `esModule` option is `true` by default, you need to change `const locals = require('./styles.css')` on ʻimport locals from './styles.css'`
1 parent f8e13c9 commit 727a24d

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = {
6767
| [**`attributes`**](#attributes) | `{Object}` | `{}` | Adds custom attributes to tag |
6868
| [**`insert`**](#insert) | `{String\|Function}` | `head` | Inserts tag at the given position into the DOM |
6969
| [**`base`**](#base) | `{Number}` | `true` | Sets module ID base (DLLPlugin) |
70-
| [**`esModule`**](#esmodule) | `{Boolean}` | `false` | Use ES modules syntax |
70+
| [**`esModule`**](#esmodule) | `{Boolean}` | `true` | Use ES modules syntax |
7171
| [**`modules`**](#modules) | `{Object}` | `undefined` | Configuration CSS Modules |
7272

7373
### `injectType`
@@ -556,12 +556,12 @@ module.exports = {
556556
### `esModule`
557557

558558
Type: `Boolean`
559-
Default: `false`
559+
Default: `true`
560560

561-
By default, `style-loader` generates JS modules that use the CommonJS modules syntax.
561+
By default, `style-loader` generates JS modules that use the ES modules syntax.
562562
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/).
563563

564-
You can enable a ES module syntax using:
564+
You can enable a CommonJS modules syntax using:
565565

566566
**webpack.config.js**
567567

@@ -573,7 +573,7 @@ module.exports = {
573573
test: /\.css$/i,
574574
loader: 'style-loader',
575575
options: {
576-
esModule: true,
576+
esModule: false,
577577
},
578578
},
579579
],

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ loaderApi.pitch = function loader(request) {
2525
: options.insert.toString();
2626
const injectType = options.injectType || 'styleTag';
2727
const esModule =
28-
typeof options.esModule !== 'undefined' ? options.esModule : false;
28+
typeof options.esModule !== 'undefined' ? options.esModule : true;
2929
const namedExport =
3030
esModule && options.modules && options.modules.namedExport;
3131
const runtimeOptions = {

test/attributes-option.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('"attributes" option', () => {
4343
expect.assertions(3);
4444

4545
const entry = getEntryByInjectType('nonce-require.js', injectType);
46-
const compiler = getCompiler(entry, { injectType });
46+
const compiler = getCompiler(entry, { injectType, esModule: false });
4747
const stats = await compile(compiler);
4848

4949
runInJsDom('main.bundle.js', compiler, stats, (dom) => {

test/insert-option.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe('"insert" option', () => {
8888

8989
const entry = getEntryByInjectType('element.js', injectType);
9090
const compiler = getCompiler(entry, {
91+
esModule: false,
9192
injectType,
9293
insert: (element) =>
9394
document.querySelector('#test-shadow').appendChild(element),

test/loader.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ describe('loader', () => {
324324

325325
const compiler = getCompiler('./lazy-negative-refs.js', {
326326
injectType,
327+
esModule: false,
327328
});
328329
const stats = await compile(compiler);
329330

0 commit comments

Comments
 (0)