Skip to content

Commit a407fab

Browse files
committed
feat: support string for 'noAssetMatch' option
1 parent a038e2e commit a407fab

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

demo/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
new InlineSourceWebpackPlugin({
2727
compress: true,
2828
rootpath: './src',
29-
noAssetMatch: 1
29+
noAssetMatch: 'warn'
3030
})
3131
],
3232
mode: 'production'

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class InlineSourceWebpackPlugin {
2020
*/
2121
_process(compilation, data, cb) {
2222
const options = Object.assign({
23-
noAssetMatch: 1,
23+
noAssetMatch: 'warn',
2424
noAssetMatchReplace: `<!-- -->`
2525
}, this.options);
2626
const handlers = [(source) => {
@@ -48,12 +48,15 @@ class InlineSourceWebpackPlugin {
4848
const noAssetMatchError = new Error(`[${this.constructor.name}]: no assets match '${asset}'.`);
4949
switch (options.noAssetMatch) {
5050
case 0:
51+
case 'none':
5152
break;
5253
case 1:
54+
case 'warn':
5355
compilation.warnings.push(noAssetMatchError);
5456
source.replace = options.noAssetMatchReplace;
5557
break;
5658
case 2:
59+
case 'error':
5760
compilation.errors.push(noAssetMatchError);
5861
source.replace = options.noAssetMatchReplace;
5962
break;

test/index.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ describe('InlineSourceWebpackPlugin', () => {
119119
});
120120
});
121121

122-
test('should ignore while "noAssetMatch" option is set to "0"', done => {
122+
123+
test('should ignore while "noAssetMatch" option is set to "0" or "none"', done => {
123124
const webpackConfig = Object.assign({}, baseWebpackConfig, {
124125
plugins: [
125126
new HtmlWebpackPlugin({
@@ -131,7 +132,7 @@ describe('InlineSourceWebpackPlugin', () => {
131132
new InlineSourceWebpackPlugin({
132133
compress: true,
133134
rootpath: './test/fixtures',
134-
noAssetMatch: 0
135+
noAssetMatch: 'none'
135136
})
136137
]
137138
});
@@ -143,7 +144,7 @@ describe('InlineSourceWebpackPlugin', () => {
143144
});
144145
});
145146

146-
test('should throw warnings and replace target while "noAssetMatch" option is set to "1"', done => {
147+
test('should throw warnings and replace target while "noAssetMatch" option is set to "1" or "warn"', done => {
147148
const webpackConfig = Object.assign({}, baseWebpackConfig, {
148149
plugins: [
149150
new HtmlWebpackPlugin({
@@ -155,7 +156,7 @@ describe('InlineSourceWebpackPlugin', () => {
155156
new InlineSourceWebpackPlugin({
156157
compress: true,
157158
rootpath: './test/fixtures',
158-
noAssetMatch: 1,
159+
noAssetMatch: 'warn',
159160
noAssetMatchReplace: '<!--inline-source-webpack-plugin-->'
160161
})
161162
]
@@ -169,7 +170,7 @@ describe('InlineSourceWebpackPlugin', () => {
169170
});
170171
});
171172

172-
test('should throw error and replace target while "noAssetMatch" option is set to "2"', done => {
173+
test('should throw error and replace target while "noAssetMatch" option is set to "2" or "error"', done => {
173174
const webpackConfig = Object.assign({}, baseWebpackConfig, {
174175
plugins: [
175176
new HtmlWebpackPlugin({
@@ -181,7 +182,7 @@ describe('InlineSourceWebpackPlugin', () => {
181182
new InlineSourceWebpackPlugin({
182183
compress: true,
183184
rootpath: './test/fixtures',
184-
noAssetMatch: 2,
185+
noAssetMatch: 'error',
185186
noAssetMatchReplace: '<!--inline-source-webpack-plugin-->'
186187
})
187188
]

0 commit comments

Comments
 (0)