Skip to content

Commit 96674f4

Browse files
committed
feat: change skipNodeModulesBundle default behavior
1 parent 1b6dfec commit 96674f4

File tree

8 files changed

+83
-7
lines changed

8 files changed

+83
-7
lines changed

examples/react/.vscode/launch.json

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
"${workspaceFolder}/dist/extension/*.js"
1717
],
1818
"preLaunchTask": "${defaultBuildTask}"
19+
},
20+
{
21+
"name": "Preview Extension",
22+
"type": "extensionHost",
23+
"request": "launch",
24+
"args": [
25+
"--extensionDevelopmentPath=${workspaceFolder}"
26+
],
27+
"outFiles": [
28+
"${workspaceFolder}/dist/extension/*.js"
29+
],
30+
"preLaunchTask": "npm: build"
1931
}
2032
]
2133
}

examples/react/.vscode/tasks.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"owner": "typescript",
1111
"fileLocation": "relative",
1212
"pattern": {
13-
"regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
13+
"regexp": "^([a-zA-Z]\\:/?([\\w\\-]/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
1414
"file": 1,
1515
"line": 3,
1616
"column": 4,
@@ -31,6 +31,15 @@
3131
"kind": "build",
3232
"isDefault": true
3333
}
34+
},
35+
{
36+
"type": "npm",
37+
"script": "build",
38+
"group": {
39+
"kind": "build",
40+
"isDefault": true
41+
},
42+
"problemMatcher": []
3443
}
3544
]
3645
}

examples/vue-import/.vscode/launch.json

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
"${workspaceFolder}/dist/extension/*.js"
1717
],
1818
"preLaunchTask": "${defaultBuildTask}"
19+
},
20+
{
21+
"name": "Preview Extension",
22+
"type": "extensionHost",
23+
"request": "launch",
24+
"args": [
25+
"--extensionDevelopmentPath=${workspaceFolder}"
26+
],
27+
"outFiles": [
28+
"${workspaceFolder}/dist/extension/*.js"
29+
],
30+
"preLaunchTask": "npm: build"
1931
}
2032
]
2133
}

examples/vue-import/.vscode/tasks.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"owner": "typescript",
1111
"fileLocation": "relative",
1212
"pattern": {
13-
"regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
13+
"regexp": "^([a-zA-Z]\\:/?([\\w\\-]/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
1414
"file": 1,
1515
"line": 3,
1616
"column": 4,
@@ -31,6 +31,15 @@
3131
"kind": "build",
3232
"isDefault": true
3333
}
34+
},
35+
{
36+
"type": "npm",
37+
"script": "build",
38+
"group": {
39+
"kind": "build",
40+
"isDefault": true
41+
},
42+
"problemMatcher": []
3443
}
3544
]
3645
}

examples/vue/.vscode/launch.json

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
"${workspaceFolder}/dist/extension/*.js"
1717
],
1818
"preLaunchTask": "${defaultBuildTask}"
19+
},
20+
{
21+
"name": "Preview Extension",
22+
"type": "extensionHost",
23+
"request": "launch",
24+
"args": [
25+
"--extensionDevelopmentPath=${workspaceFolder}"
26+
],
27+
"outFiles": [
28+
"${workspaceFolder}/dist/extension/*.js"
29+
],
30+
"preLaunchTask": "npm: build"
1931
}
2032
]
2133
}

examples/vue/.vscode/tasks.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"owner": "typescript",
1111
"fileLocation": "relative",
1212
"pattern": {
13-
"regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
13+
"regexp": "^([a-zA-Z]\\:/?([\\w\\-]/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
1414
"file": 1,
1515
"line": 3,
1616
"column": 4,
@@ -31,6 +31,15 @@
3131
"kind": "build",
3232
"isDefault": true
3333
}
34+
},
35+
{
36+
"type": "npm",
37+
"script": "build",
38+
"group": {
39+
"kind": "build",
40+
"isDefault": true
41+
},
42+
"problemMatcher": []
3443
}
3544
]
3645
}

src/index.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ function getPkg() {
2828
}
2929

3030
function preMergeOptions(options?: PluginOptions): PluginOptions {
31-
getPkg();
32-
31+
const pkg = getPkg();
3332
const opts: PluginOptions = merge(
3433
{
3534
webview: true,
@@ -43,11 +42,12 @@ function preMergeOptions(options?: PluginOptions): PluginOptions {
4342
shims: true,
4443
clean: true,
4544
dts: false,
46-
treeshake: !!isDev,
45+
treeshake: isDev ? false : 'smallest',
4746
outExtension() {
4847
return { js: '.js' };
4948
},
5049
external: ['vscode'],
50+
skipNodeModulesBundle: isDev,
5151
} as ExtensionOptions,
5252
},
5353
cloneDeep(options),
@@ -71,6 +71,12 @@ function preMergeOptions(options?: PluginOptions): PluginOptions {
7171
opt.external ?? [],
7272
);
7373

74+
if (!opt.skipNodeModulesBundle) {
75+
opt.noExternal = Object.keys(pkg.dependencies || {}).concat(
76+
Object.keys(pkg.peerDependencies || {}),
77+
);
78+
}
79+
7480
opts.extension = opt;
7581

7682
if (opts.webview === true) {

src/types.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import type { Options } from 'tsup';
44
* vscode extension options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
55
*/
66
export interface ExtensionOptions
7-
extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess'> {
7+
extends Omit<
8+
Options,
9+
'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess' | 'skipNodeModulesBundle'
10+
> {
811
/**
912
* The extension entry file.
1013
* @default "extension/index.ts"
@@ -19,6 +22,10 @@ export interface ExtensionOptions
1922
* The bundle format. Currently only supports cjs.
2023
*/
2124
format?: 'cjs';
25+
/**
26+
* Skip dependencies and peerDependencies bundle. Default is false.
27+
*/
28+
skipNodeModulesBundle?: boolean;
2229
/**
2330
* A function that will be executed after the build succeeds.
2431
*/

0 commit comments

Comments
 (0)