Skip to content

Commit 159a027

Browse files
Merge 54e7bc0 into 6ae4c3e
2 parents 6ae4c3e + 54e7bc0 commit 159a027

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ This option determines the name of non-entry chunk files.
104104

105105
Works like [`output.chunkFilename`](https://webpack.js.org/configuration/output/#outputchunkfilename)
106106

107+
#### `emitFile`
108+
109+
Type: `Boolean`
110+
Default: `true`
111+
112+
If true, emits a file (writes a file to the filesystem). If false, the plugin
113+
will extract the CSS but **will not** emit the file. It is often useful to
114+
disable this option for server-side packages.
115+
107116
#### `ignoreOrder`
108117

109118
Type: `Boolean`

src/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class MiniCssExtractPlugin {
309309
this._sortedModulesCache = new WeakMap();
310310

311311
this.options = Object.assign(
312-
{ filename: DEFAULT_FILENAME, ignoreOrder: false },
312+
{ filename: DEFAULT_FILENAME, ignoreOrder: false, emitFile: true },
313313
options
314314
);
315315

@@ -426,6 +426,7 @@ class MiniCssExtractPlugin {
426426
new CssDependencyTemplate()
427427
);
428428

429+
const { emitFile } = this.options;
429430
if (isWebpack4) {
430431
compilation.mainTemplate.hooks.renderManifest.tap(
431432
pluginName,
@@ -439,7 +440,7 @@ class MiniCssExtractPlugin {
439440
const filenameTemplate =
440441
chunk.filenameTemplate || this.options.filename;
441442

442-
if (renderedModules.length > 0) {
443+
if (renderedModules.length > 0 && emitFile) {
443444
result.push({
444445
render: () =>
445446
this.renderContentAsset(
@@ -473,7 +474,7 @@ class MiniCssExtractPlugin {
473474
const filenameTemplate =
474475
chunk.filenameTemplate || this.options.chunkFilename;
475476

476-
if (renderedModules.length > 0) {
477+
if (renderedModules.length > 0 && emitFile) {
477478
result.push({
478479
render: () =>
479480
this.renderContentAsset(
@@ -515,7 +516,7 @@ class MiniCssExtractPlugin {
515516
? this.options.filename
516517
: this.options.chunkFilename;
517518

518-
if (renderedModules.length > 0) {
519+
if (renderedModules.length > 0 && emitFile) {
519520
result.push({
520521
render: () =>
521522
this.renderContentAsset(

src/plugin-options.json

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
}
2323
]
2424
},
25+
"emitFile": {
26+
"description": "If true, emits a file (writes a file to the filesystem). If false, the plugin will extract the CSS but will not emit the file. It is often useful to disable this option for server-side packages. (https://github.com/webpack-contrib/mini-css-extract-plugin#emitFile).",
27+
"type": "boolean"
28+
},
2529
"ignoreOrder": {
2630
"type": "boolean"
2731
},

test/__snapshots__/validate-plugin-options.test.js.snap

+14-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ exports[`validate options should throw an error on the "chunkFilename" option wi
1616
* options.chunkFilename should be an instance of function."
1717
`;
1818

19+
exports[`validate options should throw an error on the "emitFile" option with "1" value 1`] = `
20+
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
21+
- options.emitFile should be a boolean.
22+
-> If true, emits a file (writes a file to the filesystem). If false, the plugin will extract the CSS but will not emit the file. It is often useful to disable this option for server-side packages. (https://github.com/webpack-contrib/mini-css-extract-plugin#emitFile)."
23+
`;
24+
1925
exports[`validate options should throw an error on the "filename" option with "true" value 1`] = `
2026
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
2127
- options.filename should be one of these:
@@ -99,47 +105,47 @@ exports[`validate options should throw an error on the "linkType" option with "i
99105
exports[`validate options should throw an error on the "unknown" option with "/test/" value 1`] = `
100106
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
101107
- options has an unknown property 'unknown'. These properties are valid:
102-
object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }"
108+
object { filename?, chunkFilename?, emitFile?, ignoreOrder?, insert?, attributes?, linkType? }"
103109
`;
104110
105111
exports[`validate options should throw an error on the "unknown" option with "[]" value 1`] = `
106112
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
107113
- options has an unknown property 'unknown'. These properties are valid:
108-
object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }"
114+
object { filename?, chunkFilename?, emitFile?, ignoreOrder?, insert?, attributes?, linkType? }"
109115
`;
110116
111117
exports[`validate options should throw an error on the "unknown" option with "{"foo":"bar"}" value 1`] = `
112118
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
113119
- options has an unknown property 'unknown'. These properties are valid:
114-
object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }"
120+
object { filename?, chunkFilename?, emitFile?, ignoreOrder?, insert?, attributes?, linkType? }"
115121
`;
116122
117123
exports[`validate options should throw an error on the "unknown" option with "{}" value 1`] = `
118124
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
119125
- options has an unknown property 'unknown'. These properties are valid:
120-
object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }"
126+
object { filename?, chunkFilename?, emitFile?, ignoreOrder?, insert?, attributes?, linkType? }"
121127
`;
122128
123129
exports[`validate options should throw an error on the "unknown" option with "1" value 1`] = `
124130
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
125131
- options has an unknown property 'unknown'. These properties are valid:
126-
object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }"
132+
object { filename?, chunkFilename?, emitFile?, ignoreOrder?, insert?, attributes?, linkType? }"
127133
`;
128134
129135
exports[`validate options should throw an error on the "unknown" option with "false" value 1`] = `
130136
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
131137
- options has an unknown property 'unknown'. These properties are valid:
132-
object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }"
138+
object { filename?, chunkFilename?, emitFile?, ignoreOrder?, insert?, attributes?, linkType? }"
133139
`;
134140
135141
exports[`validate options should throw an error on the "unknown" option with "test" value 1`] = `
136142
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
137143
- options has an unknown property 'unknown'. These properties are valid:
138-
object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }"
144+
object { filename?, chunkFilename?, emitFile?, ignoreOrder?, insert?, attributes?, linkType? }"
139145
`;
140146
141147
exports[`validate options should throw an error on the "unknown" option with "true" value 1`] = `
142148
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
143149
- options has an unknown property 'unknown'. These properties are valid:
144-
object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }"
150+
object { filename?, chunkFilename?, emitFile?, ignoreOrder?, insert?, attributes?, linkType? }"
145151
`;

test/validate-plugin-options.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ describe('validate options', () => {
2020
],
2121
failure: [true],
2222
},
23+
emitFile: {
24+
success: [true, false],
25+
failure: [1],
26+
},
2327
ignoreOrder: {
2428
success: [true, false],
2529
failure: [1],

0 commit comments

Comments
 (0)