UNPKG

1.34 kBJavaScriptView Raw
1const HandleCSSLoader = require('webpack-handle-css-loader')
2
3const LANGS = ['css', 'stylus', 'styl', 'sass', 'scss', 'less']
4
5exports.vue = function (options) {
6 const handleLoader = new HandleCSSLoader(options)
7 return handleLoader.vue()
8}
9
10// Generate loaders for standalone style files (outside of .vue)
11exports.standalone = function (config, options) {
12 const handleLoader = new HandleCSSLoader(options)
13
14 for (const lang of LANGS) {
15 const rule = handleLoader[lang]()
16 const context = config.module
17 .rule(lang)
18 .test(filepath => {
19 // Match the `test` but not ends with `.module.xxx`
20 return rule.test.test(filepath) && !/\.module\.[a-z]+$/.test(filepath)
21 })
22
23 rule.use.forEach(use => {
24 context
25 .use(use.loader)
26 .loader(use.loader)
27 .options(use.options)
28 })
29 }
30
31 handleLoader.set('cssModules', true)
32
33 const cssModulesLangs = LANGS.map(lang => [lang, new RegExp(`\\.module\\.${lang}`)])
34
35 for (const cssModulesLang of cssModulesLangs) {
36 const [lang, test] = cssModulesLang
37
38 const rule = handleLoader[lang](test)
39 const context = config.module
40 .rule(`${lang}-module`)
41 .test(rule.test)
42
43 rule.use.forEach(use => {
44 context
45 .use(use.loader)
46 .loader(use.loader)
47 .options(use.options)
48 })
49 }
50}