Skip to content

Commit 33a0bd4

Browse files
committed
fix: fix incorrect match with experiments.css enabled
1 parent d067ee5 commit 33a0bd4

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Diff for: src/pitcher.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,21 @@ export const pitch = function () {
5959

6060
// Inject style-post-loader before css-loader for scoped CSS and trimming
6161
const isWebpack5 = testWebpack5(context._compiler)
62+
const options = (getOptions(context) || {}) as VueLoaderOptions
6263
if (query.type === `style`) {
6364
if (isWebpack5 && context._compiler?.options.experiments.css) {
65+
// If user enables `experiments.css`, then we are trying to emit css code directly.
66+
// Although we can target requests like `xxx.vue?type=style` to match `type: "css"`,
67+
// it will make the plugin a mess.
68+
if (!options.experimentalInlineMatchResource) {
69+
context.emitError(
70+
new Error(
71+
'`experimentalInlineMatchResource` should be enabled if `experiments.css` enabled currently'
72+
)
73+
)
74+
return ''
75+
}
76+
6477
if (query.inline || query.module) {
6578
context.emitError(
6679
new Error(
@@ -75,7 +88,9 @@ export const pitch = function () {
7588
return typeof loader === 'string' ? loader : loader.request
7689
})
7790
.join('!')
78-
return `@import "-!${loaderString}!${context.resource}";`
91+
return `@import "${context.resourcePath}${
92+
query.lang ? `.${query.lang}` : ''
93+
}${context.resourceQuery}!=!-!${loaderString}!${context.resource}";`
7994
}
8095
const cssLoaderIndex = loaders.findIndex(isCSSLoader)
8196
if (cssLoaderIndex > -1) {

Diff for: test/utils.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ const baseConfig: webpack.Configuration = {
3838
test: /\.vue$/,
3939
use: [DEFAULT_VUE_USE],
4040
},
41-
{
42-
test: /\.css$/,
43-
use: ['style-loader', 'css-loader'],
44-
},
4541
{
4642
test: /\.ts$/,
4743
loader: process.env.WEBPACK4
@@ -80,6 +76,13 @@ export function bundle(
8076
}> {
8177
let config: BundleOptions = merge({}, baseConfig, options)
8278

79+
if (!options.experiments?.css) {
80+
config.module?.rules?.push({
81+
test: /\.css$/,
82+
use: ['style-loader', 'css-loader'],
83+
})
84+
}
85+
8386
if (config.vue && config.module) {
8487
const vueOptions = {
8588
// Test experimental inline match resource by default

0 commit comments

Comments
 (0)