Skip to content

Commit 3ba59eb

Browse files
committed
rollup mutiple inputs
1 parent 4fb24a6 commit 3ba59eb

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: WebContainers最佳实践
3+
author: yrobot
4+
keywords: WebContainers,最佳实践,vite,Stackblitz
5+
createTime: 2023年03月03日
6+
draft: true
7+
---
8+
9+
## WebContainers 是什么
10+
11+
https://webcontainers.io/guides/introduction
12+
13+
> WebContainers are a browser-based runtime for executing Node.js applications and operating system commands, entirely inside your browser tab. Apps that previously required cloud VMs to execute user code, in WebContainers can run entirely client-side with a number of benefits over the legacy cloud VM.
14+
15+
WebContainers 是一个基于浏览器的运行时,可以在浏览器中执行 Node.js 应用程序和操作系统命令。与传统的云虚拟机相比,WebContainers 可以在浏览器中完全运行,具有更多的优势。
16+
17+
### 相比云虚拟机的优势
18+
19+
- 在浏览器中本地化的运行 Node.js 工具链(例如 Webpack、Vite 等)
20+
- 安全性:一切都运行在在浏览器中
21+
- 快速:毫秒级启动开发环境
22+
- 开源免费
23+
24+
## 限制
25+
26+
### 1. 需要为网站文件配置 COOP/COEP 头
27+
28+
https://webcontainers.io/guides/configuring-headers
29+
30+
需要给网站文件配置 Header
31+
32+
```yaml
33+
Cross-Origin-Embedder-Policy: require-corp
34+
Cross-Origin-Opener-Policy: same-origin
35+
```

_blogs/库开发/库开发过程中遇到的坑.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,42 @@ ls ~/.config/yarn/link
101101
```bash
102102
rm -rf ~/.config/yarn/link/[node-name]
103103
```
104+
105+
## 使用 Rollup 打包 多个 inputs,@rollup/plugin-node-resolve 失效(output 仍包含 require)
106+
107+
### 解决方案:每个 input 分到一个独立打包进程
108+
109+
`rollup.config.ts`
110+
111+
```ts
112+
import ts from "rollup-plugin-ts";
113+
114+
import resolve from "@rollup/plugin-node-resolve";
115+
import commonjs from "@rollup/plugin-commonjs";
116+
117+
const inputs = [
118+
{
119+
file1: "src/file1.ts",
120+
},
121+
{
122+
file2: "src/file2.ts",
123+
},
124+
];
125+
126+
export default inputs.map((input) => ({
127+
input,
128+
output: {
129+
dir: "build",
130+
format: "cjs",
131+
entryFileNames: "[name].js",
132+
chunkFileNames: "[name].js",
133+
},
134+
plugins: [
135+
ts({
136+
tsconfig: "tsconfig.json",
137+
}),
138+
resolve(),
139+
commonjs(),
140+
],
141+
}));
142+
```

0 commit comments

Comments
 (0)