File tree Expand file tree Collapse file tree 4 files changed +497
-124
lines changed Expand file tree Collapse file tree 4 files changed +497
-124
lines changed Original file line number Diff line number Diff line change 18
18
- run : yarn install
19
19
- run : yarn run:webpack
20
20
- run : yarn run:esbuild
21
+ - run : yarn run:vite
Original file line number Diff line number Diff line change 5
5
"type" : " module" ,
6
6
"packageManager" : " yarn@4.1.1" ,
7
7
"devDependencies" : {
8
- "@node-rs/argon2" : " ^1.7.2 " ,
8
+ "@node-rs/argon2" : " ^1.8.0 " ,
9
9
"@types/webpack" : " ^5.28.5" ,
10
+ "builtin-modules" : " ^3.3.0" ,
10
11
"esbuild" : " ^0.20.1" ,
11
12
"node-loader" : " ^2.0.0" ,
12
- "rollup" : " ^4.12.0" ,
13
+ "rollup" : " ^4.13.0" ,
14
+ "vite" : " ^5.1.6" ,
13
15
"webpack" : " ^5.90.3" ,
14
16
"webpack-cli" : " ^5.1.4"
15
17
},
16
18
"scripts" : {
17
19
"run:esbuild" : " yarn esbuild --bundle src/index.js --outfile=dist/esbuild.cjs --platform=node --loader:.node=copy --format=cjs && node dist/esbuild.cjs" ,
20
+ "run:vite" : " yarn vite build && node dist/vite.cjs" ,
18
21
"run:webpack" : " webpack --mode=production && node dist/bundled.cjs"
19
22
}
20
23
}
Original file line number Diff line number Diff line change
1
+ import { existsSync } from "node:fs" ;
2
+ import { readFile } from "node:fs/promises" ;
3
+ import { basename } from "node:path" ;
4
+
5
+ import { Plugin , defineConfig } from "vite" ;
6
+ import builtinModules from "builtin-modules" ;
7
+
8
+ const ViteNodeAddonPlugin = ( ) : Plugin => {
9
+ return {
10
+ name : "native-addon" ,
11
+ apply : "build" ,
12
+ enforce : "pre" ,
13
+ async load ( id ) {
14
+ if ( id . endsWith ( ".node" ) && existsSync ( id ) ) {
15
+ const refId = this . emitFile ( {
16
+ type : "asset" ,
17
+ fileName : basename ( id ) ,
18
+ source : await readFile ( id ) ,
19
+ } ) ;
20
+ const runtimePath = `./${ this . getFileName ( refId ) } ` ;
21
+ return (
22
+ `const id = ${ JSON . stringify ( runtimePath ) } ;` +
23
+ `export default require(id);`
24
+ ) ;
25
+ }
26
+ return null ;
27
+ } ,
28
+ } ;
29
+ } ;
30
+
31
+ export default defineConfig ( {
32
+ resolve : {
33
+ mainFields : [ "module" , "main" ] ,
34
+ } ,
35
+ plugins : [ ViteNodeAddonPlugin ( ) ] ,
36
+ build : {
37
+ rollupOptions : {
38
+ input : "./src/index.js" ,
39
+ output : {
40
+ format : "cjs" ,
41
+ entryFileNames : "vite.cjs" ,
42
+ } ,
43
+ } ,
44
+ target : "esnext" ,
45
+ ssr : true ,
46
+ ssrEmitAssets : true ,
47
+ } ,
48
+ ssr : {
49
+ external : builtinModules as string [ ] ,
50
+ noExternal : true ,
51
+ } ,
52
+ } ) ;
You can’t perform that action at this time.
0 commit comments