File tree 2 files changed +23
-5
lines changed
2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -59,8 +59,21 @@ export const pitch = function () {
59
59
60
60
// Inject style-post-loader before css-loader for scoped CSS and trimming
61
61
const isWebpack5 = testWebpack5 ( context . _compiler )
62
+ const options = ( getOptions ( context ) || { } ) as VueLoaderOptions
62
63
if ( query . type === `style` ) {
63
64
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
+
64
77
if ( query . inline || query . module ) {
65
78
context . emitError (
66
79
new Error (
@@ -75,7 +88,9 @@ export const pitch = function () {
75
88
return typeof loader === 'string' ? loader : loader . request
76
89
} )
77
90
. join ( '!' )
78
- return `@import "-!${ loaderString } !${ context . resource } ";`
91
+ return `@import "${ context . resourcePath } ${
92
+ query . lang ? `.${ query . lang } ` : ''
93
+ } ${ context . resourceQuery } !=!-!${ loaderString } !${ context . resource } ";`
79
94
}
80
95
const cssLoaderIndex = loaders . findIndex ( isCSSLoader )
81
96
if ( cssLoaderIndex > - 1 ) {
Original file line number Diff line number Diff line change @@ -38,10 +38,6 @@ const baseConfig: webpack.Configuration = {
38
38
test : / \. v u e $ / ,
39
39
use : [ DEFAULT_VUE_USE ] ,
40
40
} ,
41
- {
42
- test : / \. c s s $ / ,
43
- use : [ 'style-loader' , 'css-loader' ] ,
44
- } ,
45
41
{
46
42
test : / \. t s $ / ,
47
43
loader : process . env . WEBPACK4
@@ -80,6 +76,13 @@ export function bundle(
80
76
} > {
81
77
let config : BundleOptions = merge ( { } , baseConfig , options )
82
78
79
+ if ( ! options . experiments ?. css ) {
80
+ config . module ?. rules ?. push ( {
81
+ test : / \. c s s $ / ,
82
+ use : [ 'style-loader' , 'css-loader' ] ,
83
+ } )
84
+ }
85
+
83
86
if ( config . vue && config . module ) {
84
87
const vueOptions = {
85
88
// Test experimental inline match resource by default
You can’t perform that action at this time.
0 commit comments