@hanzo/vite 0.1.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/LICENSE.md +21 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 hanzo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The subset of a Vite config this package touches. Structural on purpose: it
|
|
2
|
+
* must not pin a `vite` version to type-check. */
|
|
3
|
+
export type Config = Record<string, unknown>;
|
|
4
|
+
export type Options = {
|
|
5
|
+
/** App root — where src lives. Almost always `import.meta.dirname`. */
|
|
6
|
+
root: string;
|
|
7
|
+
/** Source aliases, resolved against `root`. Defaults to `~` → `<root>/src`. */
|
|
8
|
+
alias?: Record<string, string>;
|
|
9
|
+
/** Extra packages to force to a single copy, on top of the runtime family. */
|
|
10
|
+
dedupe?: string[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Wrap an app's own Vite config with the shared answers.
|
|
14
|
+
*
|
|
15
|
+
* The app WINS on every key it states; `resolve` is merged rather than replaced,
|
|
16
|
+
* and the app's own aliases come FIRST so it can override one of ours.
|
|
17
|
+
*/
|
|
18
|
+
export declare function hanzo(config: Config | undefined, options: Options): Config;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA;mDACmD;AACnD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE5C,MAAM,MAAM,OAAO,GAAG;IACpB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAQD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,YAAK,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAqBnE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hanzo/vite — the Vite config every Hanzo app shares.
|
|
3
|
+
*
|
|
4
|
+
* import { hanzo } from '@hanzo/vite'
|
|
5
|
+
* export default hanzo(myOwnConfig, { root: import.meta.dirname })
|
|
6
|
+
*
|
|
7
|
+
* The @hanzo/next twin, for the apps that are not Next. Same four answers,
|
|
8
|
+
* because the problems belong to the STACK, not to the bundler:
|
|
9
|
+
*
|
|
10
|
+
* 1. `~/…` is this app's own source. Vite reads no tsconfig `paths` of its own
|
|
11
|
+
* (that needs a plugin), so declaring it here means one answer whether the
|
|
12
|
+
* host is Next, Vite, or vitest — and it stops depending on which TypeScript
|
|
13
|
+
* is installed, which under 7 answers nothing at all.
|
|
14
|
+
*
|
|
15
|
+
* 2. `react-native` means `react-native-web` on the web, EXACT match only, so a
|
|
16
|
+
* deep `react-native/Libraries/*` import still finds the real package. Vite's
|
|
17
|
+
* alias array takes a RegExp for that; the bare-string form is a prefix match
|
|
18
|
+
* and would rewrite the deep imports too.
|
|
19
|
+
*
|
|
20
|
+
* 3. `.web.*` first, so a package's web implementation wins over its native one.
|
|
21
|
+
*
|
|
22
|
+
* 4. ONE copy of the gui runtime. `dedupe` names the packages whose identity is
|
|
23
|
+
* load-bearing: two copies of a React context provider are two contexts, and
|
|
24
|
+
* the failure is not a crash — it is a component that renders unstyled, or a
|
|
25
|
+
* hook that reads a default nobody set.
|
|
26
|
+
*
|
|
27
|
+
* `preserveSymlinks: false` is Vite's default and is CORRECT here, unlike the
|
|
28
|
+
* webpack side: Vite dedupes by resolved id, so `dedupe` does the work that
|
|
29
|
+
* keeping symlinks does under webpack. One runtime either way, two mechanisms —
|
|
30
|
+
* because the bundlers genuinely differ, not because we changed our minds.
|
|
31
|
+
*/
|
|
32
|
+
import { resolve } from 'node:path';
|
|
33
|
+
/** Packages whose identity is load-bearing: a second copy breaks context. */
|
|
34
|
+
const RUNTIME = ['react', 'react-dom', 'react-native-web', '@hanzo/gui', '@hanzo/ui'];
|
|
35
|
+
const WEB_FIRST = ['.web.tsx', '.web.ts', '.web.jsx', '.web.js'];
|
|
36
|
+
const DEFAULT_EXT = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
|
|
37
|
+
/**
|
|
38
|
+
* Wrap an app's own Vite config with the shared answers.
|
|
39
|
+
*
|
|
40
|
+
* The app WINS on every key it states; `resolve` is merged rather than replaced,
|
|
41
|
+
* and the app's own aliases come FIRST so it can override one of ours.
|
|
42
|
+
*/
|
|
43
|
+
export function hanzo(config = {}, options) {
|
|
44
|
+
const { root, alias = { '~': './src' }, dedupe = [] } = options;
|
|
45
|
+
const appResolve = config.resolve ?? {};
|
|
46
|
+
// Vite matches an alias array in order and a RegExp entry exactly, which is
|
|
47
|
+
// what keeps `react-native/Libraries/*` resolving to the real package.
|
|
48
|
+
const aliases = [
|
|
49
|
+
...(Array.isArray(appResolve.alias) ? appResolve.alias : []),
|
|
50
|
+
...Object.entries(alias).map(([find, to]) => ({ find, replacement: resolve(root, to) })),
|
|
51
|
+
{ find: /^react-native$/, replacement: 'react-native-web' },
|
|
52
|
+
];
|
|
53
|
+
return {
|
|
54
|
+
...config,
|
|
55
|
+
resolve: {
|
|
56
|
+
...appResolve,
|
|
57
|
+
alias: aliases,
|
|
58
|
+
dedupe: [...new Set([...RUNTIME, ...dedupe, ...(appResolve.dedupe ?? [])])],
|
|
59
|
+
extensions: appResolve.extensions ?? [...WEB_FIRST, ...DEFAULT_EXT],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAenC,6EAA6E;AAC7E,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,YAAY,EAAE,WAAW,CAAC,CAAA;AAErF,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,S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package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzo/vite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The Vite config every Hanzo app shares — one runtime, one compiler, one way.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"vite": ">=6"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^7.0.2",
|
|
23
|
+
"vitest": "^3.2.4"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/hanzoai/ui.git",
|
|
31
|
+
"directory": "pkgs/vite"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|