Skip to content

Commit d4e84b4

Browse files
committed
chore: update
1 parent 4768204 commit d4e84b4

File tree

3 files changed

+35
-178
lines changed

3 files changed

+35
-178
lines changed

website/docs/en/config/lib/shims.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
overviewHeaders: [2, 3]
3+
---
4+
15
# lib.shims
26

37
- **Type:**

website/docs/zh/config/lib/shims.mdx

Lines changed: 4 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,178 +1,5 @@
1-
# lib.shims
2-
3-
- **Type:**
4-
5-
```ts
6-
type Shims = {
7-
cjs?: {
8-
'import.meta.url'?: boolean;
9-
};
10-
esm?: {
11-
__filename?: boolean;
12-
__dirname?: boolean;
13-
require?: boolean;
14-
};
15-
};
16-
```
17-
18-
- **Default:**
19-
20-
```js
21-
{
22-
cjs: {
23-
'import.meta.url': true,
24-
},
25-
esm: {
26-
__filename: false,
27-
__dirname: false,
28-
require: false,
29-
},
30-
}
31-
```
32-
33-
Used to configure the shims for CommonJS and ESM output.
34-
35-
## shims.cjs
36-
37-
Set the fields to `true` to enable the corresponding shims for CommonJS output.
38-
39-
### shims.cjs['import.meta.url']
40-
41-
- **Default:** `true`
42-
43-
Options:
44-
45-
- `true`: when `format` is `cjs`, the `import.meta.url` in source code will be replaced with the URL of the current module.
46-
47-
For example, given the following source code:
48-
49-
```js
50-
import { readFileSync } from 'fs';
51-
const buffer = readFileSync(new URL('./data.proto', import.meta.url));
52-
```
53-
54-
the CJS output will be transformed to:
55-
56-
```js
57-
const { readFileSync } = require('fs');
58-
const buffer = readFileSync(
59-
new URL(
60-
'./data.proto',
61-
/*#__PURE__*/ (function () {
62-
return typeof document === 'undefined'
63-
? new (module.require('url'.replace('', '')).URL)(
64-
'file:' + __filename,
65-
).href
66-
: (document.currentScript && document.currentScript.src) ||
67-
new URL('main.js', document.baseURI).href;
68-
})(),
69-
),
70-
);
71-
```
72-
73-
- `false`: the `import.meta.url` will be leave as is, which will cause a runtime error when running the output.
74-
75-
## shims.esm
76-
77-
Set the fields to `true` to enable the corresponding shims for ESM output.
78-
79-
### shims.esm.\_\_filename
80-
81-
Whether to shim the global `__filename` of CommonJS in ESM output.
82-
83-
- **Default:** `false`
84-
85-
Options:
86-
87-
- `true`: when `format` is `esm`, the `__filename` in source code will be replaced with the filename of the current module.
88-
89-
For example, given the following source code:
1+
---
2+
overviewHeaders: [2, 3]
3+
---
904

91-
```js
92-
console.log(__filename);
93-
```
94-
95-
the ESM output will be transformed to:
96-
97-
```js
98-
import { fileURLToPath as __webpack_fileURLToPath__ } from 'url';
99-
import { dirname as __webpack_dirname__ } from 'path';
100-
var src_dirname = __webpack_dirname__(
101-
__webpack_fileURLToPath__(import.meta.url),
102-
);
103-
var src_filename = __webpack_fileURLToPath__(import.meta.url);
104-
console.log(src_filename);
105-
```
106-
107-
- `false`: the `__filename` will be leave as is, which will cause a runtime error when running the output.
108-
109-
### shims.esm.\_\_dirname
110-
111-
Whether to shim the global `__dirname` of CommonJS in ESM output.
112-
113-
- **Default:** `false`
114-
115-
Options:
116-
117-
- `true`: when `format` is `esm`, the `__dirname` in source code will be replaced with the directory name of the current module.
118-
119-
For example, given the following source code:
120-
121-
```js
122-
console.log(__dirname);
123-
```
124-
125-
the ESM output will be transformed to:
126-
127-
```js
128-
import { fileURLToPath as __webpack_fileURLToPath__ } from 'url';
129-
import { dirname as __webpack_dirname__ } from 'path';
130-
var src_dirname = __webpack_dirname__(
131-
__webpack_fileURLToPath__(import.meta.url),
132-
);
133-
console.log(src_dirname);
134-
```
135-
136-
- `false`: the `__dirname` will be leave as is, which will cause a runtime error when running the output.
137-
138-
### shims.esm.require
139-
140-
Whether to shim the global `require` of CommonJS in ESM output.
141-
142-
- **Default:** `false`
143-
144-
Options:
145-
146-
- `true`: when `format` is `esm`, there will be a `require` that created by `createRequire` at the beginning of the output which can be accessed in source code like the global `require` like CommonJS.
147-
148-
For example, given the following source code:
149-
150-
```js
151-
const someModule = require('./someModule');
152-
153-
// dynamic require
154-
const dynamicRequiredModule = require(SOME_VALUE_IN_RUNTIME);
155-
// require.resolve
156-
const someModulePath = require.resolve('./someModule');
157-
// use require as a expression
158-
const lazyFn = (module, requireFn) => {};
159-
lazyFn('./other.js', require);
160-
```
161-
162-
the ESM output will be transformed to:
163-
164-
```js
165-
import __rslib_shim_module__ from 'module';
166-
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(
167-
import.meta.url,
168-
);
169-
// dynamic require
170-
require(SOME_VALUE_IN_RUNTIME);
171-
// require.resolve
172-
require.resolve('./someModule');
173-
// use require as a expression
174-
const lazyFn = (module, requireFn) => {};
175-
lazyFn('./other.js', require);
176-
```
177-
178-
- `false`: the `require` will be leave as is, which will cause a runtime error when running the output.
5+
# lib.shims

website/theme/index.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1+
import { Announcement } from '@rstack-dev/doc-ui/announcement';
12
import { NavIcon } from '@rstack-dev/doc-ui/nav-icon';
3+
import { NoSSR, useLang, usePageData } from 'rspress/runtime';
24
import Theme from 'rspress/theme';
35
import { HomeLayout } from './pages';
46
import './index.scss';
57

6-
const Layout = () => <Theme.Layout beforeNavTitle={<NavIcon />} />;
8+
const ANNOUNCEMENT_URL = '/';
9+
10+
const Layout = () => {
11+
const { page } = usePageData();
12+
const lang = useLang();
13+
return (
14+
<Theme.Layout
15+
beforeNavTitle={<NavIcon />}
16+
beforeNav={
17+
<NoSSR>
18+
<Announcement
19+
href={ANNOUNCEMENT_URL}
20+
message={
21+
lang === 'en'
22+
? '🚧 Rslib documentation is under construction, stay tuned for a stable version!'
23+
: '🚧 Rslib 中文文档正在施工中,可以先查阅英文文档'
24+
}
25+
localStorageKey="rslib-announcement-closed"
26+
display={page.pageType === 'home'}
27+
/>
28+
</NoSSR>
29+
}
30+
/>
31+
);
32+
};
733

834
export default {
935
...Theme,

0 commit comments

Comments
 (0)