forked from startupjs/startupjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstylPlugin.js
29 lines (28 loc) · 996 Bytes
/
stylPlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import callLoader from '@startupjs/bundler/lib/callLoader.js'
import stylusToCssLoader from '@startupjs/bundler/lib/stylusToCssLoader.js'
import cssToReactNativeLoader from '@startupjs/bundler/lib/cssToReactNativeLoader.js'
export default function viteTransformStartupjsStyl () {
return {
name: 'startupjs:styl',
configResolved (config) {
config.plugins = config.plugins.filter(plugin => {
if (['vite:css', 'vite:css-post'].includes(plugin.name)) return
return true
})
},
async transform (code, filename) {
if (!(
/\.styl$/.test(filename) &&
!/\.module\.styl/.test(filename)
)) return
code = callLoader(stylusToCssLoader, code, filename, { platform: 'web' })
code = callLoader(cssToReactNativeLoader, code, filename)
// transform from cjs to mjs format
code = code.replace(/module\.exports\s*=\s*/, 'export default ')
return {
code,
map: { mappings: '' }
}
}
}
}