File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { existsSync , readFileSync } from 'node:fs'
2
+ import { builtinModules } from 'node:module'
2
3
import { join } from 'node:path'
3
4
import type { Plugin } from 'vite'
4
5
5
6
interface UserOptions {
6
7
deps : boolean ,
8
+ nodeBuiltins : boolean ,
7
9
optionalDeps : boolean ,
8
10
peerDeps : boolean ,
9
11
useFile : string ,
@@ -16,6 +18,7 @@ const parseFile = (file: string) => {
16
18
export const externalizeDeps = ( options : Partial < UserOptions > = { } ) : Plugin => {
17
19
const optionsResolved : UserOptions = {
18
20
deps : true ,
21
+ nodeBuiltins : true ,
19
22
optionalDeps : true ,
20
23
peerDeps : true ,
21
24
useFile : join ( process . cwd ( ) , 'package.json' ) ,
@@ -38,6 +41,14 @@ export const externalizeDeps = (options: Partial<UserOptions> = {}): Plugin => {
38
41
} )
39
42
}
40
43
44
+ if ( optionsResolved . nodeBuiltins ) {
45
+ builtinModules . forEach ( ( builtinModule ) => {
46
+ const builtinMatcher = new RegExp ( `^(?:node:)?${ builtinModule } $` )
47
+
48
+ externalDeps . add ( builtinMatcher )
49
+ } )
50
+ }
51
+
41
52
if ( optionsResolved . optionalDeps ) {
42
53
Object . keys ( optionalDependencies ) . forEach ( ( dep ) => {
43
54
const depMatcher = new RegExp ( `^${ dep } (?:/.+)?$` )
Original file line number Diff line number Diff line change
1
+ import path from 'path'
2
+ import path2 from 'node:path'
3
+ import { resolve } from 'path'
1
4
import chalk from 'chalk'
2
5
3
- console . log ( chalk . green ( 'hello' ) )
6
+ console . log ( path , path2 , resolve , chalk )
You can’t perform that action at this time.
0 commit comments