@anaemia/bundler 0.3.6 → 0.3.7
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1
- package/dist/router/scan.d.ts.map +1 -1
- package/dist/router/scan.js +5 -2
- package/package.json +2 -2
- package/src/index.ts +24 -1
- package/src/router/scan.ts +9 -3
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,cAAc,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAqB1D,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,cAAc,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAqB1D,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAuK1H;AAED,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
18
18
|
const __dirname = path.dirname(__filename);
|
|
19
19
|
export async function getRspackConfig(appRoot, config = {}) {
|
|
20
20
|
const isDev = process.env.NODE_ENV !== "production";
|
|
21
|
+
const rawEnv = process.env;
|
|
21
22
|
const coreRuntimeDir = path.dirname(require.resolve("@anaemia/core/package.json"));
|
|
22
23
|
const runtimeDir = path.resolve(coreRuntimeDir, "./dist/runtime");
|
|
23
24
|
const routes = await scanRoutes(appRoot);
|
|
@@ -33,6 +34,25 @@ export async function getRspackConfig(appRoot, config = {}) {
|
|
|
33
34
|
const extraClientBabelPlugins = config.plugins?.flatMap((p) => p.babelPlugins?.client ?? []) ?? [];
|
|
34
35
|
const extraServerBabelPlugins = config.plugins?.flatMap((p) => p.babelPlugins?.server ?? []) ?? [];
|
|
35
36
|
const solidRefreshPlugin = [require.resolve("solid-refresh/babel"), { bundler: "rspack-esm", jsx: false }];
|
|
37
|
+
// env processing
|
|
38
|
+
const serverEnv = {
|
|
39
|
+
MODE: JSON.stringify(process.env.NODE_ENV || "development"),
|
|
40
|
+
DEV: JSON.stringify(isDev),
|
|
41
|
+
PROD: JSON.stringify(!isDev),
|
|
42
|
+
};
|
|
43
|
+
for (const key in rawEnv) {
|
|
44
|
+
serverEnv[key] = JSON.stringify(rawEnv[key]);
|
|
45
|
+
}
|
|
46
|
+
const clientEnv = {
|
|
47
|
+
MODE: JSON.stringify(process.env.NODE_ENV || "development"),
|
|
48
|
+
DEV: JSON.stringify(isDev),
|
|
49
|
+
PROD: JSON.stringify(!isDev),
|
|
50
|
+
};
|
|
51
|
+
for (const key in rawEnv) {
|
|
52
|
+
if (key.startsWith("PUBLIC_")) {
|
|
53
|
+
clientEnv[key] = JSON.stringify(rawEnv[key]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
36
56
|
const sharedResolve = {
|
|
37
57
|
extensions: [".tsx", ".ts", ".jsx", ".js", ".json", ".scss", ".css"],
|
|
38
58
|
extensionAlias: { ".js": [".ts", ".js"], ".jsx": [".tsx", ".jsx"] },
|
|
@@ -81,6 +101,7 @@ export async function getRspackConfig(appRoot, config = {}) {
|
|
|
81
101
|
new rspack.DefinePlugin({
|
|
82
102
|
__ANAEMIA_RUNTIME_CONFIG__: JSON.stringify({ port: config.port, assets: config.assets, styles: config.styles }),
|
|
83
103
|
...config.define?.client,
|
|
104
|
+
"import.meta.env": clientEnv,
|
|
84
105
|
}),
|
|
85
106
|
new rspack.NormalModuleReplacementPlugin(/^node:/, (resource) => {
|
|
86
107
|
resource.request = resource.request.replace(/^node:/, "");
|
|
@@ -130,7 +151,7 @@ export async function getRspackConfig(appRoot, config = {}) {
|
|
|
130
151
|
__anaemia_server_routes__: serverRoutesFile,
|
|
131
152
|
},
|
|
132
153
|
},
|
|
133
|
-
plugins: [new rspack.DefinePlugin({ ...config.define?.server })],
|
|
154
|
+
plugins: [new rspack.DefinePlugin({ ...config.define?.server, "import.meta.env": serverEnv })],
|
|
134
155
|
module: {
|
|
135
156
|
parser: { "css/auto": { namedExports: false } },
|
|
136
157
|
rules: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/router/scan.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAezD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/router/scan.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAezD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAkBpE;AAUD,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAiE/E"}
|
package/dist/router/scan.js
CHANGED
|
@@ -14,10 +14,13 @@ const CATCH_ALL_FILE = /^\[\.\.\.(.+?)\]\.(tsx|jsx)$/;
|
|
|
14
14
|
const DYNAMIC_SEGMENT = /^\[(.+?)\]\.(tsx|jsx)$/;
|
|
15
15
|
export function scanServerRoutes(appRoot) {
|
|
16
16
|
const routesDir = path.resolve(appRoot, "./src/routes");
|
|
17
|
-
const files = glob.sync("**/_route.{ts,tsx}", { cwd: routesDir, posix: true });
|
|
17
|
+
const files = glob.sync("**/_route.{ts,tsx,js,jsx}", { cwd: routesDir, posix: true });
|
|
18
18
|
return files.map((file) => {
|
|
19
19
|
const dir = path.dirname(file);
|
|
20
|
-
const
|
|
20
|
+
const normalizedDir = dir
|
|
21
|
+
.replace(/\[\.\.\.(.+?)\]/g, "*")
|
|
22
|
+
.replace(/\[(.+?)\]/g, ":$1");
|
|
23
|
+
const urlPattern = normalizedDir === "." ? "/" : `/${normalizedDir}`;
|
|
21
24
|
return {
|
|
22
25
|
urlPattern,
|
|
23
26
|
filePath: path.resolve(routesDir, file),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anaemia/bundler",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@anaemia/core": "^0.3.
|
|
14
|
+
"@anaemia/core": "^0.3.7",
|
|
15
15
|
"@babel/core": "^7.29.7",
|
|
16
16
|
"@babel/preset-typescript": "^7.29.7",
|
|
17
17
|
"@rspack/core": "^2.0.5",
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ const __dirname = path.dirname(__filename);
|
|
|
24
24
|
|
|
25
25
|
export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {}): Promise<[Configuration, Configuration]> {
|
|
26
26
|
const isDev = process.env.NODE_ENV !== "production";
|
|
27
|
+
const rawEnv = process.env;
|
|
27
28
|
const coreRuntimeDir = path.dirname(require.resolve("@anaemia/core/package.json"));
|
|
28
29
|
const runtimeDir = path.resolve(coreRuntimeDir, "./dist/runtime");
|
|
29
30
|
|
|
@@ -43,6 +44,27 @@ export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {
|
|
|
43
44
|
const extraServerBabelPlugins = config.plugins?.flatMap((p) => p.babelPlugins?.server ?? []) ?? [];
|
|
44
45
|
const solidRefreshPlugin = [require.resolve("solid-refresh/babel"), { bundler: "rspack-esm", jsx: false }];
|
|
45
46
|
|
|
47
|
+
// env processing
|
|
48
|
+
const serverEnv: Record<string, string> = {
|
|
49
|
+
MODE: JSON.stringify(process.env.NODE_ENV || "development"),
|
|
50
|
+
DEV: JSON.stringify(isDev),
|
|
51
|
+
PROD: JSON.stringify(!isDev),
|
|
52
|
+
};
|
|
53
|
+
for (const key in rawEnv) {
|
|
54
|
+
serverEnv[key] = JSON.stringify(rawEnv[key]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const clientEnv: Record<string, string> = {
|
|
58
|
+
MODE: JSON.stringify(process.env.NODE_ENV || "development"),
|
|
59
|
+
DEV: JSON.stringify(isDev),
|
|
60
|
+
PROD: JSON.stringify(!isDev),
|
|
61
|
+
};
|
|
62
|
+
for (const key in rawEnv) {
|
|
63
|
+
if (key.startsWith("PUBLIC_")) {
|
|
64
|
+
clientEnv[key] = JSON.stringify(rawEnv[key]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
46
68
|
const sharedResolve = {
|
|
47
69
|
extensions: [".tsx", ".ts", ".jsx", ".js", ".json", ".scss", ".css"],
|
|
48
70
|
extensionAlias: { ".js": [".ts", ".js"], ".jsx": [".tsx", ".jsx"] },
|
|
@@ -92,6 +114,7 @@ export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {
|
|
|
92
114
|
new rspack.DefinePlugin({
|
|
93
115
|
__ANAEMIA_RUNTIME_CONFIG__: JSON.stringify({ port: config.port, assets: config.assets, styles: config.styles }),
|
|
94
116
|
...config.define?.client,
|
|
117
|
+
"import.meta.env": clientEnv,
|
|
95
118
|
}),
|
|
96
119
|
new rspack.NormalModuleReplacementPlugin(/^node:/, (resource) => {
|
|
97
120
|
resource.request = resource.request.replace(/^node:/, "");
|
|
@@ -143,7 +166,7 @@ export async function getRspackConfig(appRoot: string, config: AnaemiaConfig = {
|
|
|
143
166
|
__anaemia_server_routes__: serverRoutesFile,
|
|
144
167
|
},
|
|
145
168
|
},
|
|
146
|
-
plugins: [new rspack.DefinePlugin({ ...config.define?.server })],
|
|
169
|
+
plugins: [new rspack.DefinePlugin({ ...config.define?.server, "import.meta.env": serverEnv })],
|
|
147
170
|
module: {
|
|
148
171
|
parser: { "css/auto": { namedExports: false } },
|
|
149
172
|
rules: [
|
package/src/router/scan.ts
CHANGED
|
@@ -50,11 +50,17 @@ const DYNAMIC_SEGMENT = /^\[(.+?)\]\.(tsx|jsx)$/;
|
|
|
50
50
|
|
|
51
51
|
export function scanServerRoutes(appRoot: string): ServerRouteEntry[] {
|
|
52
52
|
const routesDir = path.resolve(appRoot, "./src/routes");
|
|
53
|
-
const files = glob.sync("**/_route.{ts,tsx}", { cwd: routesDir, posix: true });
|
|
54
|
-
|
|
53
|
+
const files = glob.sync("**/_route.{ts,tsx,js,jsx}", { cwd: routesDir, posix: true });
|
|
54
|
+
|
|
55
55
|
return files.map((file) => {
|
|
56
56
|
const dir = path.dirname(file);
|
|
57
|
-
|
|
57
|
+
|
|
58
|
+
const normalizedDir = dir
|
|
59
|
+
.replace(/\[\.\.\.(.+?)\]/g, "*")
|
|
60
|
+
.replace(/\[(.+?)\]/g, ":$1");
|
|
61
|
+
|
|
62
|
+
const urlPattern = normalizedDir === "." ? "/" : `/${normalizedDir}`;
|
|
63
|
+
|
|
58
64
|
return {
|
|
59
65
|
urlPattern,
|
|
60
66
|
filePath: path.resolve(routesDir, file),
|