File tree 4 files changed +62
-0
lines changed
4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1
1
const { attrsToQuery } = require ( './utils' )
2
2
const hotReloadAPIPath = JSON . stringify ( require . resolve ( 'vue-hot-reload-api' ) )
3
+ const nonWhitespaceRE = / \S + /
3
4
4
5
module . exports = function genStyleInjectionCode (
5
6
loaderContext ,
@@ -69,6 +70,8 @@ module.exports = function genStyleInjectionCode (
69
70
}
70
71
}
71
72
73
+ // filter out empty styles (with no `src` specified or only contains whitespaces)
74
+ styles = styles . filter ( style => style . src || nonWhitespaceRE . test ( style . content ) )
72
75
// explicit injection is needed in SSR (for critical CSS collection)
73
76
// or in Shadow Mode (for injection into shadow root)
74
77
// In these modes, vue-style-loader exports objects with the __inject__
Original file line number Diff line number Diff line change @@ -137,6 +137,38 @@ test('extract CSS', done => {
137
137
} )
138
138
} )
139
139
140
+ test ( 'extract CSS with code spliting' , done => {
141
+ bundle ( {
142
+ entry : 'extract-css-chunks.vue' ,
143
+ modify : config => {
144
+ config . module . rules = [
145
+ {
146
+ test : / \. v u e $ / ,
147
+ use : 'vue-loader'
148
+ } ,
149
+ {
150
+ test : / \. c s s $ / ,
151
+ use : [
152
+ MiniCssExtractPlugin . loader ,
153
+ 'css-loader'
154
+ ]
155
+ }
156
+ ]
157
+ } ,
158
+ plugins : [
159
+ new MiniCssExtractPlugin ( {
160
+ filename : 'test.output.css'
161
+ } )
162
+ ]
163
+ } , code => {
164
+ const css = normalizeNewline ( mfs . readFileSync ( '/test.output.css' ) . toString ( ) )
165
+ expect ( css ) . toContain ( `h1 {\n color: red;\n}` )
166
+ expect ( mfs . existsSync ( '/empty.test.output.css' ) ) . toBe ( false )
167
+ expect ( mfs . existsSync ( '/basic.test.output.css' ) ) . toBe ( true )
168
+ done ( )
169
+ } )
170
+ } )
171
+
140
172
test ( 'support rules with oneOf' , async ( ) => {
141
173
const run = ( entry , assert ) => new Promise ( ( resolve , reject ) => {
142
174
mockBundleAndRun ( {
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <h1 >empty style</h1 >
3
+ </template >
4
+
5
+ <style >
6
+ </style >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div >
3
+ <basic ></basic >
4
+ <empty-style ></empty-style >
5
+ </div >
6
+ </template >
7
+
8
+ <script >
9
+ export default {
10
+ components: {
11
+ Basic : () => import (/* webpackChunkName: "basic" */ ' ./basic.vue' ),
12
+ EmptyStyle : () => import (/* webpackChunkName: "empty" */ ' ./empty-style.vue' )
13
+ }
14
+ }
15
+ </script >
16
+
17
+ <style >
18
+ h1 {
19
+ color : red ;
20
+ }
21
+ </style >
You can’t perform that action at this time.
0 commit comments