+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "lazySingletonStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "lazySingletonStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "lazyStyleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "lazyStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "lazyStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "linkTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "linkTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "linkTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "singletonStyleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "singletonStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "singletonStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "styleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "styleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work when not specified and when the "injectType" option is "styleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazySingletonStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "lazyStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "linkTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "singletonStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "false" and when the "injectType" option is "styleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazySingletonStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "lazyStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "linkTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "singletonStyleTag": warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag" and CommonJS module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag" and CommonJS module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag" and CommonJS module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag" and ES module syntax used: DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag" and ES module syntax used: errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag" and ES module syntax used: warnings 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag": DOM 1`] = `
+"
+ style-loader test
+
+
+
+
Body
+
+
+
+
+"
+`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag": errors 1`] = `Array []`;
+
+exports[`"esModule" option should work with a value equal to "true" and when the "injectType" option is "styleTag": warnings 1`] = `Array []`;
diff --git a/test/__snapshots__/validate-options.test.js.snap b/test/__snapshots__/validate-options.test.js.snap
index 749d3d72..cd4bcc60 100644
--- a/test/__snapshots__/validate-options.test.js.snap
+++ b/test/__snapshots__/validate-options.test.js.snap
@@ -7,6 +7,12 @@ exports[`validate options should throw an error on the "attributes" option with
-> Adds custom attributes to tag (https://github.com/webpack-contrib/style-loader#attributes)."
`;
+exports[`validate options should throw an error on the "esModule" option with "true" value 1`] = `
+"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
+ - options.esModule should be a boolean.
+ -> Use the ES modules syntax (https://github.com/webpack-contrib/css-loader#esmodule)."
+`;
+
exports[`validate options should throw an error on the "injectType" option with "unknown" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options.injectType should be one of these:
@@ -27,47 +33,47 @@ exports[`validate options should throw an error on the "insert" option with "tru
exports[`validate options should throw an error on the "unknown" option with "/test/" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'unknown'. These properties are valid:
- object { injectType?, attributes?, insert?, base? }"
+ object { injectType?, attributes?, insert?, base?, esModule? }"
`;
exports[`validate options should throw an error on the "unknown" option with "[]" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'unknown'. These properties are valid:
- object { injectType?, attributes?, insert?, base? }"
+ object { injectType?, attributes?, insert?, base?, esModule? }"
`;
exports[`validate options should throw an error on the "unknown" option with "{"foo":"bar"}" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'unknown'. These properties are valid:
- object { injectType?, attributes?, insert?, base? }"
+ object { injectType?, attributes?, insert?, base?, esModule? }"
`;
exports[`validate options should throw an error on the "unknown" option with "{}" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'unknown'. These properties are valid:
- object { injectType?, attributes?, insert?, base? }"
+ object { injectType?, attributes?, insert?, base?, esModule? }"
`;
exports[`validate options should throw an error on the "unknown" option with "1" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'unknown'. These properties are valid:
- object { injectType?, attributes?, insert?, base? }"
+ object { injectType?, attributes?, insert?, base?, esModule? }"
`;
exports[`validate options should throw an error on the "unknown" option with "false" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'unknown'. These properties are valid:
- object { injectType?, attributes?, insert?, base? }"
+ object { injectType?, attributes?, insert?, base?, esModule? }"
`;
exports[`validate options should throw an error on the "unknown" option with "test" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'unknown'. These properties are valid:
- object { injectType?, attributes?, insert?, base? }"
+ object { injectType?, attributes?, insert?, base?, esModule? }"
`;
exports[`validate options should throw an error on the "unknown" option with "true" value 1`] = `
"Invalid options object. Style Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'unknown'. These properties are valid:
- object { injectType?, attributes?, insert?, base? }"
+ object { injectType?, attributes?, insert?, base?, esModule? }"
`;
diff --git a/test/esModule-option.test.js b/test/esModule-option.test.js
new file mode 100644
index 00000000..a052afc1
--- /dev/null
+++ b/test/esModule-option.test.js
@@ -0,0 +1,209 @@
+import path from 'path';
+
+import {
+ compile,
+ getCompiler,
+ getEntryByInjectType,
+ getErrors,
+ getWarnings,
+ runInJsDom,
+} from './helpers/index';
+
+describe('"esModule" option', () => {
+ const injectTypes = [
+ 'styleTag',
+ 'singletonStyleTag',
+ 'lazyStyleTag',
+ 'lazySingletonStyleTag',
+ 'linkTag',
+ ];
+
+ injectTypes.forEach((injectType) => {
+ it(`should work when not specified and when the "injectType" option is "${injectType}"`, async () => {
+ const entry = getEntryByInjectType('simple.js', injectType);
+ const compiler = getCompiler(entry, { injectType });
+ const stats = await compile(compiler);
+
+ runInJsDom('main.bundle.js', compiler, stats, (dom) => {
+ expect(dom.serialize()).toMatchSnapshot('DOM');
+ });
+
+ expect(getWarnings(stats)).toMatchSnapshot('warnings');
+ expect(getErrors(stats)).toMatchSnapshot('errors');
+ });
+
+ it(`should work with a value equal to "true" and when the "injectType" option is "${injectType}"`, async () => {
+ const entry = getEntryByInjectType('simple.js', injectType);
+ const compiler = getCompiler(entry, { injectType, esModule: true });
+ const stats = await compile(compiler);
+
+ runInJsDom('main.bundle.js', compiler, stats, (dom) => {
+ expect(dom.serialize()).toMatchSnapshot('DOM');
+ });
+
+ expect(getWarnings(stats)).toMatchSnapshot('warnings');
+ expect(getErrors(stats)).toMatchSnapshot('errors');
+ });
+
+ it(`should work with a value equal to "true" and when the "injectType" option is "${injectType}" and ES module syntax used`, async () => {
+ const entry = getEntryByInjectType('simple.js', injectType);
+ const compiler = getCompiler(
+ entry,
+ { injectType },
+ {
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ use: [
+ {
+ loader: path.resolve(__dirname, '../src/cjs.js'),
+ options: { injectType, esModule: true },
+ },
+ injectType === 'linkTag'
+ ? { loader: 'file-loader', options: { esModule: true } }
+ : { loader: 'css-loader', options: { esModule: true } },
+ ],
+ },
+ ],
+ },
+ }
+ );
+ const stats = await compile(compiler);
+
+ runInJsDom('main.bundle.js', compiler, stats, (dom) => {
+ expect(dom.serialize()).toMatchSnapshot('DOM');
+ });
+
+ expect(getWarnings(stats)).toMatchSnapshot('warnings');
+ expect(getErrors(stats)).toMatchSnapshot('errors');
+ });
+
+ it(`should work with a value equal to "true" and when the "injectType" option is "${injectType}" and CommonJS module syntax used`, async () => {
+ const entry = getEntryByInjectType('simple.js', injectType);
+ const compiler = getCompiler(
+ entry,
+ { injectType },
+ {
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ use: [
+ {
+ loader: path.resolve(__dirname, '../src/cjs.js'),
+ options: { injectType, esModule: true },
+ },
+ injectType === 'linkTag'
+ ? {
+ loader: 'file-loader',
+ options: { esModule: false },
+ }
+ : {
+ loader: 'css-loader',
+ options: { esModule: false },
+ },
+ ],
+ },
+ ],
+ },
+ }
+ );
+ const stats = await compile(compiler);
+
+ runInJsDom('main.bundle.js', compiler, stats, (dom) => {
+ expect(dom.serialize()).toMatchSnapshot('DOM');
+ });
+
+ expect(getWarnings(stats)).toMatchSnapshot('warnings');
+ expect(getErrors(stats)).toMatchSnapshot('errors');
+ });
+
+ it(`should work with a value equal to "false" and when the "injectType" option is "${injectType}"`, async () => {
+ const entry = getEntryByInjectType('simple.js', injectType);
+ const compiler = getCompiler(entry, { injectType, esModule: false });
+ const stats = await compile(compiler);
+
+ runInJsDom('main.bundle.js', compiler, stats, (dom) => {
+ expect(dom.serialize()).toMatchSnapshot('DOM');
+ });
+
+ expect(getWarnings(stats)).toMatchSnapshot('warnings');
+ expect(getErrors(stats)).toMatchSnapshot('errors');
+ });
+
+ it(`should work with a value equal to "false" and when the "injectType" option is "${injectType}" and ES module syntax used`, async () => {
+ const entry = getEntryByInjectType('simple.js', injectType);
+ const compiler = getCompiler(
+ entry,
+ { injectType },
+ {
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ use: [
+ {
+ loader: path.resolve(__dirname, '../src/cjs.js'),
+ options: { injectType, esModule: false },
+ },
+ injectType === 'linkTag'
+ ? { loader: 'file-loader', options: { esModule: true } }
+ : { loader: 'css-loader', options: { esModule: true } },
+ ],
+ },
+ ],
+ },
+ }
+ );
+ const stats = await compile(compiler);
+
+ runInJsDom('main.bundle.js', compiler, stats, (dom) => {
+ expect(dom.serialize()).toMatchSnapshot('DOM');
+ });
+
+ expect(getWarnings(stats)).toMatchSnapshot('warnings');
+ expect(getErrors(stats)).toMatchSnapshot('errors');
+ });
+
+ it(`should work with a value equal to "false" and when the "injectType" option is "${injectType}" and CommonJS module syntax used`, async () => {
+ const entry = getEntryByInjectType('simple.js', injectType);
+ const compiler = getCompiler(
+ entry,
+ { injectType },
+ {
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ use: [
+ {
+ loader: path.resolve(__dirname, '../src/cjs.js'),
+ options: { injectType, esModule: false },
+ },
+ injectType === 'linkTag'
+ ? {
+ loader: 'file-loader',
+ options: { esModule: false },
+ }
+ : {
+ loader: 'css-loader',
+ options: { esModule: false },
+ },
+ ],
+ },
+ ],
+ },
+ }
+ );
+ const stats = await compile(compiler);
+
+ runInJsDom('main.bundle.js', compiler, stats, (dom) => {
+ expect(dom.serialize()).toMatchSnapshot('DOM');
+ });
+
+ expect(getWarnings(stats)).toMatchSnapshot('warnings');
+ expect(getErrors(stats)).toMatchSnapshot('errors');
+ });
+ });
+});
diff --git a/test/manual/webpack.config.js b/test/manual/webpack.config.js
index f66938a9..74afa9f9 100644
--- a/test/manual/webpack.config.js
+++ b/test/manual/webpack.config.js
@@ -10,6 +10,11 @@ const ENABLE_ES_MODULE =
? Boolean(process.env.ES_MODULE)
: false;
+const ENABLE_PREVIOUS_ES_MODULE =
+ typeof process.env.PREVIOUS_ES_MODULE !== 'undefined'
+ ? Boolean(process.env.PREVIOUS_ES_MODULE)
+ : false;
+
module.exports = {
devtool: ENABLE_SOURCE_MAP ? 'source-map' : false,
mode: 'development',
@@ -29,12 +34,13 @@ module.exports = {
use: [
{
loader: require.resolve('../../dist/cjs.js'),
+ options: { esModule: ENABLE_ES_MODULE },
},
{
loader: 'css-loader',
options: {
sourceMap: ENABLE_SOURCE_MAP,
- esModule: ENABLE_ES_MODULE,
+ esModule: ENABLE_PREVIOUS_ES_MODULE,
},
},
],
@@ -45,12 +51,13 @@ module.exports = {
use: [
{
loader: require.resolve('../../dist/cjs.js'),
+ options: { esModule: ENABLE_ES_MODULE },
},
{
loader: 'css-loader',
options: {
sourceMap: ENABLE_SOURCE_MAP,
- esModule: ENABLE_ES_MODULE,
+ esModule: ENABLE_PREVIOUS_ES_MODULE,
modules: true,
},
},
@@ -61,13 +68,13 @@ module.exports = {
use: [
{
loader: require.resolve('../../dist/cjs.js'),
- options: { injectType: 'lazyStyleTag' },
+ options: { injectType: 'lazyStyleTag', esModule: ENABLE_ES_MODULE },
},
{
loader: 'css-loader',
options: {
sourceMap: ENABLE_SOURCE_MAP,
- esModule: ENABLE_ES_MODULE,
+ esModule: ENABLE_PREVIOUS_ES_MODULE,
},
},
],
@@ -77,13 +84,13 @@ module.exports = {
use: [
{
loader: require.resolve('../../dist/cjs.js'),
- options: { injectType: 'lazyStyleTag' },
+ options: { injectType: 'lazyStyleTag', esModule: ENABLE_ES_MODULE },
},
{
loader: 'css-loader',
options: {
sourceMap: ENABLE_SOURCE_MAP,
- esModule: ENABLE_ES_MODULE,
+ esModule: ENABLE_PREVIOUS_ES_MODULE,
modules: true,
},
},
@@ -95,10 +102,11 @@ module.exports = {
use: [
{
loader: require.resolve('../../dist/cjs.js'),
- options: { injectType: 'linkTag' },
+ options: { injectType: 'linkTag', esModule: ENABLE_ES_MODULE },
},
{
loader: 'file-loader',
+ options: { esModule: ENABLE_PREVIOUS_ES_MODULE },
},
],
},
@@ -108,12 +116,13 @@ module.exports = {
use: [
{
loader: require.resolve('../../dist/cjs.js'),
+ options: { esModule: ENABLE_ES_MODULE },
},
{
loader: 'css-loader',
options: {
sourceMap: ENABLE_SOURCE_MAP,
- esModule: ENABLE_ES_MODULE,
+ esModule: ENABLE_PREVIOUS_ES_MODULE,
},
},
{
@@ -131,13 +140,13 @@ module.exports = {
use: [
{
loader: require.resolve('../../dist/cjs.js'),
- options: { injectType: 'lazyStyleTag' },
+ options: { injectType: 'lazyStyleTag', esModule: ENABLE_ES_MODULE },
},
{
loader: 'css-loader',
options: {
sourceMap: ENABLE_SOURCE_MAP,
- esModule: ENABLE_ES_MODULE,
+ esModule: ENABLE_PREVIOUS_ES_MODULE,
},
},
{
diff --git a/test/validate-options.test.js b/test/validate-options.test.js
index 940cb836..b066a5a7 100644
--- a/test/validate-options.test.js
+++ b/test/validate-options.test.js
@@ -20,6 +20,10 @@ describe('validate options', () => {
success: ['selector', () => {}],
failure: [true],
},
+ esModule: {
+ success: [true, false],
+ failure: ['true'],
+ },
unknown: {
success: [],
failure: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }],