@@ -13,6 +13,23 @@ const isVirtualModule = (request?: string) => {
13
13
return request . includes ( '/node_modules/.virtual' ) ;
14
14
} ;
15
15
16
+ // Preprocessor defined rule in `lib` field will be suffixed with self-increasing serial number.
17
+ // e.g. less, less-1, sass-2.
18
+ const isPreprocessorRule = (
19
+ preprocessRuleId : string ,
20
+ toMatchRuleId : string ,
21
+ ) => {
22
+ if ( preprocessRuleId === toMatchRuleId ) {
23
+ return true ;
24
+ }
25
+
26
+ if ( new RegExp ( `${ preprocessRuleId } -\\d` ) . test ( toMatchRuleId ) ) {
27
+ return true ;
28
+ }
29
+
30
+ return false ;
31
+ } ;
32
+
16
33
const isScopedStyle = ( request ?: string ) => {
17
34
if ( ! request ) return false ;
18
35
@@ -28,16 +45,38 @@ export const pluginUnpluginVue = ({
28
45
const callerName = api . context . callerName ;
29
46
const isRslib = callerName === 'rslib' ;
30
47
48
+ api . modifyEnvironmentConfig ( {
49
+ handler : ( config ) => {
50
+ config . output . target = 'web' ;
51
+ } ,
52
+ order : 'default' ,
53
+ } ) ;
54
+
31
55
api . modifyRspackConfig ( ( config ) => {
32
56
// Not using webpack-chain here.
33
57
// https://github.com/neutrinojs/webpack-chain/issues/352
34
58
config . plugins ?. push ( RspackPluginVue ( unpluginVueOptions ) ) ;
35
59
} ) ;
36
60
37
- api . modifyBundlerChain ( ( config , { CHAIN_ID } ) => {
38
- const baseRule = config . module . rules . get ( CHAIN_ID . RULE . CSS ) ;
39
- baseRule . enforce ( 'post' ) ;
40
- config . resolve . extensions . add ( '.vue' ) ;
61
+ api . modifyBundlerChain ( {
62
+ handler : ( config , { CHAIN_ID } ) => {
63
+ for ( const ruleId in config . module . rules . entries ( ) ) {
64
+ if (
65
+ CHAIN_ID . RULE . CSS === ruleId ||
66
+ isPreprocessorRule ( CHAIN_ID . RULE . LESS , ruleId ) ||
67
+ isPreprocessorRule ( CHAIN_ID . RULE . SASS , ruleId ) ||
68
+ isPreprocessorRule ( CHAIN_ID . RULE . STYLUS , ruleId )
69
+ ) {
70
+ const baseRule = config . module . rules . get ( ruleId ) ;
71
+ if ( baseRule ) {
72
+ baseRule . enforce ( 'post' ) ;
73
+ }
74
+ }
75
+ }
76
+
77
+ config . resolve . extensions . add ( '.vue' ) ;
78
+ } ,
79
+ order : 'post' ,
41
80
} ) ;
42
81
43
82
// Rslib bundleless specific config, will only be used in bundleless mode
@@ -68,34 +107,6 @@ export const pluginUnpluginVue = ({
68
107
}
69
108
}
70
109
} ) ;
71
-
72
- // api.modifyBundlerChain((config, { CHAIN_ID }) => {
73
- // const cssRule = config.module.rules.get(CHAIN_ID.RULE.CSS);
74
- // const vueCssRule = config.module
75
- // .rule('vue-scoped-css')
76
- // .test((value) => {
77
- // const matched = /lang\.css$/.test(value);
78
- // if (matched) {
79
- // }
80
- // return isStyle(value);
81
- // })
82
- // .before(CHAIN_ID.RULE.CSS)
83
- // .merge(cssRule.entries());
84
- // const ruleId = CHAIN_ID.RULE.CSS;
85
- // const rule = config.module.rule(ruleId);
86
- // const rspackPath = require.resolve('@rspack/core');
87
- // // TODO: hard coded loader path
88
- // const loaderPath = path.resolve(rspackPath, '../cssExtractLoader.js');
89
- // if (rule.uses.has(CHAIN_ID.USE.MINI_CSS_EXTRACT)) {
90
- // rule
91
- // .use(CHAIN_ID.USE.MINI_CSS_EXTRACT)
92
- // .loader(loaderPath)
93
- // .options({});
94
- // }
95
- // for (const use of cssRule.uses.values()) {
96
- // vueCssRule.use(use.name).merge(use.entries());
97
- // }
98
- // });
99
110
}
100
111
} ,
101
112
} ) ;
0 commit comments