You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the [format](/config/lib/format)is set to `cjs`or`esm`, Rslib treats the output as an mid-level artifact that will be consumed by other build tools again. During the code transformation, Rslib transforms the source file into a JS file and a static asset file that is output according to [output.distPath](/config/rsbuild/output#outputdistpath), which is used to preserve the `import`statements for static assets.
40
40
41
-
下面是一个使用示例,假设源码如下:
41
+
The following is an example of usage, assuming the source code is as follows:
When the [format](/config/lib/format)is`cjs`or`esm`, Rslib treats the output as an intermediate product that will be consumed again by other packaging tools. Rslib preserves relative reference paths in CSS outputs by setting [output.assetPrefix](/config/rsbuild/output#outputassetprefix)to`"auto"`.
127
127
128
-
下面是一个使用示例,假设源码如下:
128
+
The following is an example of usage, assuming the source code is as follows:
129
129
130
130
<Tabs>
131
131
<Tablabel="src/index.css">
@@ -147,7 +147,7 @@ export { logo_rslib_entry_namespaceObject as default };
147
147
</Tab>
148
148
</Tabs>
149
149
150
-
会打包出如下产物:
150
+
The following output will be packaged:
151
151
152
152
<Tabs>
153
153
@@ -174,9 +174,9 @@ export { logo_rslib_entry_namespaceObject as default };
174
174
175
175
---
176
176
177
-
### 在 CSS 中忽略某些文件引用
177
+
### Ignore some assets imported in CSS
178
178
179
-
如果需要在 CSS 文件中引用绝对路径下的静态资源:
179
+
If you need to import a static asset with an absolute path in a CSS file:
180
180
181
181
```css
182
182
@font-face {
@@ -185,7 +185,7 @@ export { logo_rslib_entry_namespaceObject as default };
By default, the built-in `css-loader`in Rslib will resolve absolute paths in `url()`and look for the specified modules. If you want to skip resolving absolute paths, you can configure [`tools.cssLoader`](/config/rsbuild/tools#toolscssloader)to filter out the specified paths. The filtered paths are left as they are in the code.
When developing libraries that will be consumed again by other build tools as intermediate products, static assets are typically not inlined, leaving the handling and optimization to the build tools on the application side.
The automatic inlining size threshold can be modified via the [output.dataUriLimit](/config/rsbuild/output#outputdataurilimit)configuration option. When the [format](/config/lib/format)is`cjs`or`esm`, Rslib defaults the `output.dataUriLimit`to`0`, not inlining any static assets.
212
212
213
-
## 构建产物目录
213
+
## Build Output Directory
214
214
215
-
当静态资源被引用后,会自动被输出到构建产物的目录下,你可以:
215
+
Once static assets are referenced, they will automatically be output to the build output directory. You can:
To fix this, you need to add a type declaration file for the static assets, please create a `src/env.d.ts`file, and add the corresponding type declaration.
After adding the type declaration, if the type error still exists, you can try to restart the current IDE, or adjust the directory where `env.d.ts`is located, making sure the TypeScript can correctly identify the type definition.
247
247
248
-
## 扩展静态资源类型
248
+
## Extend asset types
249
249
250
-
如果 Rslib 内置的静态资源类型不能满足你的需求,可以通过以下方式扩展额外的静态资源类型。
250
+
If the built-in static assets type of Rslib does not meet your needs, you can extend the additional static assets type in the following ways.
By using the [source.assetsInclude](/config/rsbuild/source#sourceassetsinclude)config, you can specify additional file types to be treated as static assets.
255
255
256
256
```ts title="rslib.config.ts"
257
257
exportdefault {
@@ -261,19 +261,19 @@ export default {
261
261
};
262
262
```
263
263
264
-
添加以上配置后,你就可以在代码里引用 `*.pdf`文件了,比如:
264
+
After adding the above configuration, you can import `*.pdf`files in your code, for example:
0 commit comments