File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change
1
+ import fs from "node:fs" ;
2
+ import { createRequire } from "node:module" ;
1
3
import { fileURLToPath } from "node:url" ;
2
4
import { bundleAsync } from "lightningcss" ;
3
5
6
+ const require = createRequire ( import . meta. url ) ;
7
+
8
+ /**
9
+ * Resolve path to file in `node_modules`
10
+ * @param {string } filePath - File path
11
+ * @returns {string } Resolved file path
12
+ * @example `@import url("~codemirror/lib/codemirror.css");`
13
+ */
14
+ function resolveModuleFilePath ( filePath ) {
15
+ if ( filePath . includes ( "~" ) ) {
16
+ const moduleFilePath = filePath . split ( "~" ) [ 1 ] ;
17
+ return require . resolve ( moduleFilePath ) ;
18
+ }
19
+
20
+ return filePath ;
21
+ }
22
+
4
23
let { code } = await bundleAsync ( {
5
24
filename : fileURLToPath ( new URL ( "../styles/app.css" , import . meta. url ) ) ,
6
25
minify : true ,
26
+ resolver : {
27
+ read ( filePath ) {
28
+ filePath = resolveModuleFilePath ( filePath ) ;
29
+ return fs . readFileSync ( filePath , "utf8" ) ;
30
+ } ,
31
+ } ,
7
32
} ) ;
8
33
9
34
export const styles = ( ) => code . toString ( ) ;
Original file line number Diff line number Diff line change 1
- @import url ("../../../../node_modules/ codemirror/lib/codemirror.css" );
1
+ @import url ("~ codemirror/lib/codemirror.css" );
2
2
3
3
.CodeMirror {
4
4
--fieldset-flow-space : 0 ;
You can’t perform that action at this time.
0 commit comments