@pob/rollup-esbuild 10.1.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/lib/createRollupConfig.js +23 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,3 +35,27 @@ export default createRollupConfig({
|
|
|
35
35
|
plugins: [watch && run({ execArgv: ["--enable-source-maps"] })],
|
|
36
36
|
});
|
|
37
37
|
```
|
|
38
|
+
|
|
39
|
+
## Target-specific files
|
|
40
|
+
|
|
41
|
+
Each env of `pob.envs` resolves a file in this order, `.ts` standing for every
|
|
42
|
+
source extension:
|
|
43
|
+
|
|
44
|
+
| target | resolution order |
|
|
45
|
+
| -------------- | ---------------------------------------------------------------- |
|
|
46
|
+
| `browser` | `.web.target-browser.ts`, `.target-browser.ts`, `.web.ts`, `.ts` |
|
|
47
|
+
| `node` | `.web.target-node.ts`, `.target-node.ts`, `.web.ts`, `.ts` |
|
|
48
|
+
| `react-native` | `.target-react-native.ts`, `.ts` |
|
|
49
|
+
|
|
50
|
+
- `.target-<target>` selects by runtime: put code needing browser globals
|
|
51
|
+
(`window`, `document`, `localStorage`) in `.target-browser` files, and code
|
|
52
|
+
needing Node APIs in `.target-node` files.
|
|
53
|
+
- `.web` selects by platform, as react-native does: the react-native-web
|
|
54
|
+
variant of a component. The `node` build includes it, because its consumer is
|
|
55
|
+
web server rendering (expo-router static output resolves the `node` export on
|
|
56
|
+
the server), which must render the tree the `browser` build hydrates. A `.web`
|
|
57
|
+
file must therefore not touch browser globals outside of effects and event
|
|
58
|
+
handlers.
|
|
59
|
+
|
|
60
|
+
Pass `getExtensions(extensions, env)` to `createRollupConfig` to resolve
|
|
61
|
+
differently.
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { chmodSync, readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
createSourceWorkspaceDependencies,
|
|
5
|
+
nodeFormatToExt,
|
|
6
|
+
resolveEntry,
|
|
7
|
+
} from "@pob/rollup";
|
|
4
8
|
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
5
9
|
import replace from "@rollup/plugin-replace";
|
|
6
10
|
import configExternalDependencies from "rollup-config-external-dependencies";
|
|
@@ -11,11 +15,12 @@ export default function createRollupConfig({
|
|
|
11
15
|
outDirectory = "dist",
|
|
12
16
|
pkg = JSON.parse(readFileSync(path.join(cwd, "package.json"))),
|
|
13
17
|
plugins = [],
|
|
18
|
+
// `.web` is the react-native-web platform: node builds it too, as web server
|
|
19
|
+
// rendering must output the tree the browser build hydrates. Code needing a
|
|
20
|
+
// browser runtime goes in `.target-browser` files.
|
|
14
21
|
getExtensions = (extensions, { target }) => {
|
|
15
|
-
if (target === "
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
return extensions;
|
|
22
|
+
if (target === "react-native") return extensions;
|
|
23
|
+
return extensions.flatMap((ext) => [`.web${ext}`, `${ext}`]);
|
|
19
24
|
},
|
|
20
25
|
}) {
|
|
21
26
|
const pobConfig = pkg.pob;
|
|
@@ -25,7 +30,17 @@ export default function createRollupConfig({
|
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
const jsx = pobConfig.jsx;
|
|
28
|
-
const
|
|
33
|
+
const sourceWorkspaceDependencies = createSourceWorkspaceDependencies(
|
|
34
|
+
cwd,
|
|
35
|
+
pkg,
|
|
36
|
+
);
|
|
37
|
+
const externalByPackageJson = configExternalDependencies([
|
|
38
|
+
pkg,
|
|
39
|
+
...sourceWorkspaceDependencies.pkgs,
|
|
40
|
+
]);
|
|
41
|
+
const external = (id) =>
|
|
42
|
+
!sourceWorkspaceDependencies.isSourceWorkspaceDependency(id) &&
|
|
43
|
+
externalByPackageJson(id);
|
|
29
44
|
|
|
30
45
|
const createConfigForEnv = (entry, entryPath, env) => {
|
|
31
46
|
const extensions = getExtensions(
|
|
@@ -70,8 +85,9 @@ export default function createRollupConfig({
|
|
|
70
85
|
warn(warning);
|
|
71
86
|
},
|
|
72
87
|
|
|
73
|
-
external
|
|
88
|
+
external,
|
|
74
89
|
plugins: [
|
|
90
|
+
sourceWorkspaceDependencies.plugin,
|
|
75
91
|
esbuild({
|
|
76
92
|
loaders: {
|
|
77
93
|
// https://github.com/egoist/rollup-plugin-esbuild/issues/384
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pob/rollup-esbuild",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "rollup configuration with typescript for pob",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/christophehurpeau/pob",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@pob/rollup": "8.3.0",
|
|
42
43
|
"@rollup/plugin-node-resolve": "16.0.3",
|
|
43
44
|
"@rollup/plugin-replace": "6.0.3",
|
|
44
45
|
"@rollup/plugin-run": "3.1.0",
|
|
45
46
|
"esbuild": "0.28.2",
|
|
46
47
|
"rollup": "4.60.4",
|
|
47
48
|
"rollup-config-external-dependencies": "^3.0.1",
|
|
48
|
-
"rollup-plugin-esbuild": "6.2.1"
|
|
49
|
-
"@pob/rollup": "8.2.0"
|
|
49
|
+
"rollup-plugin-esbuild": "6.2.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"rollup": "4.60.4",
|