Skip to content

Commit 239072a

Browse files
committed
docs: update structure / format / 3rd deps / glossary / TS
1 parent 1c1aeb7 commit 239072a

File tree

19 files changed

+342
-29
lines changed

19 files changed

+342
-29
lines changed

packages/core/src/types/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type AutoExternal =
4141
| boolean
4242
| {
4343
dependencies?: boolean;
44+
optionalDependencies?: boolean;
4445
devDependencies?: boolean;
4546
peerDependencies?: boolean;
4647
};

packages/create-rslib/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ async function getTemplateName({ template }: Argv) {
3737
}),
3838
);
3939

40+
const language = checkCancel<string>(
41+
await select({
42+
message: 'Select language',
43+
options: [
44+
{ value: 'ts', label: 'TypeScript' },
45+
{ value: 'js', label: 'JavaScript' },
46+
],
47+
}),
48+
);
49+
4050
const supportStorybook = templateName === 'react';
4151

4252
type ExcludesFalse = <T>(x: T | false) => x is T;
@@ -56,16 +66,6 @@ async function getTemplateName({ template }: Argv) {
5666
}),
5767
);
5868

59-
const language = checkCancel<string>(
60-
await select({
61-
message: 'Select language',
62-
options: [
63-
{ value: 'ts', label: 'TypeScript' },
64-
{ value: 'js', label: 'JavaScript' },
65-
],
66-
}),
67-
);
68-
6969
return composeTemplateName({
7070
template: templateName,
7171
lang: language as Lang,

scripts/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ unencapsulated
131131
unocss
132132
unpatch
133133
unplugin
134+
unpredictibly
134135
unshift
135136
upath
136137
vitest

website/docs/en/guide/advanced/_meta.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
"package-json",
3-
"templates",
43
"third-party-deps",
54
"polyfill",
65
"css",

website/docs/en/guide/advanced/templates.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,81 @@
11
# Handle Third-party Dependencies
2+
3+
Generally, third-party dependencies required by a project can be installed via the `install` command in the package manager. After the third-party dependencies are successfully installed, they will generally appear under `dependencies` and `devDependencies` in the project `package.json`.
4+
5+
```json title="package.json"
6+
{
7+
"dependencies": {},
8+
"devDependencies": {}
9+
}
10+
```
11+
12+
Dependencies under `"dependencies"` are generally related to project code and builds, and if these third-party dependencies are declared under `"devDependencies"`, then there will be missing dependencies in production runtime.
13+
14+
In addition to `"dependencies"`, `"peerDependencies"`can also declare dependencies that are needed in the production environment, but it puts more emphasis on the existence of these dependencies declared by `"peerDependencies"` in the project's runtime environment, similar to the plugin mechanism.
15+
16+
## Default handling of third-party dependencies
17+
18+
By default, **third-party dependencies under `"dependencies"`, `"optionalDependencies"` and `"peerDependencies"` are not bundled by Rslib**.
19+
20+
This is because when the npm package is installed, its `"dependencies"` will also be installed. By not packaging `"dependencies"`, you can reduce the size of the package product.
21+
22+
If you need to package some dependencies, it is recommended to move them from `"dependencies"` to `"devDependencies"`, which is equivalent to **prebundle** the dependencies and reduces the size of the dependency installation.
23+
24+
### Example
25+
26+
If the project has a dependency on `react`.
27+
28+
```json title="package.json"
29+
{
30+
"dependencies": {
31+
"react": "^18"
32+
},
33+
// or
34+
"peerDependencies": {
35+
"react": "^18"
36+
}
37+
}
38+
```
39+
40+
When a `react` dependency is used in the source code:
41+
42+
```tsx title="src/index.ts"
43+
import React from 'react';
44+
console.info(React);
45+
```
46+
47+
The `react` code will not be bundled into the output:
48+
49+
```js title="dist/index.js"
50+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from 'react';
51+
console.info(__WEBPACK_EXTERNAL_MODULE_react__['default']);
52+
```
53+
54+
If you want to modify the default processing, you can use the following API.
55+
56+
- [`lib.autoExternal`](/config/lib/auto-external)
57+
58+
## Exclude specified third-party dependencies
59+
60+
We previously introduced the use of [`lib.autoExternal`](/config/lib/auto-external). This configuration lets you manage third-party dependencies more precisely.
61+
62+
For example, when we need to leave only certain dependencies unbundled, we can configure it as follows.
63+
64+
:::tip
65+
In this case, some dependencies may not be suitable for bundling. If so, you can handle it as follows.
66+
:::
67+
68+
```ts
69+
export default defineConfig({
70+
lib: [
71+
{
72+
// ...
73+
autoExternal: true,
74+
output: {
75+
externals: ['pkg-1', /pkg-2/],
76+
},
77+
// ...
78+
},
79+
],
80+
});
81+
```
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[
22
"cli",
33
"configure-rslib",
4-
"typescript-usage",
5-
"output-files",
6-
"bundle-mode",
4+
"typescript",
5+
"output-format",
6+
"output-structure",
77
"upgrade-rslib",
8-
"cjs-esm",
98
"umd"
109
]

website/docs/en/guide/basic/bundle-mode.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.

website/docs/en/guide/basic/cjs-esm.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.

website/docs/en/guide/basic/output-files.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)