@rsaf/bundler 0.0.3 → 0.0.4
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/bundler/config.d.ts +12 -0
- package/dist/bundler/config.js +114 -0
- package/dist/config/esbuild.d.ts +31 -0
- package/dist/config/esbuild.js +43 -0
- package/dist/config/path.d.ts +38 -0
- package/dist/config/path.js +67 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/types/config.d.ts +9 -14
- package/package.json +3 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ESBuildClientDevConfig, ESBuildClientProdConfig, ESBuildServerDevConfig, ESBuildServerProdConfig } from '../types/config.js';
|
|
2
|
+
export declare function createClientConfig(env: 'dev' | 'prod', options: {
|
|
3
|
+
absWorkingDir: string;
|
|
4
|
+
entryPoints: string[] | Record<string, string>;
|
|
5
|
+
}): ESBuildClientDevConfig | ESBuildClientProdConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Return configuration to create server bundler
|
|
8
|
+
*/
|
|
9
|
+
export declare function createServerConfig(env: 'dev' | 'prod', options: {
|
|
10
|
+
absWorkingDir: string;
|
|
11
|
+
entryPoints: string[] | Record<string, string>;
|
|
12
|
+
}): ESBuildServerDevConfig | ESBuildServerProdConfig;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ASSET_LOADERS, BASE_LOADERS, ESBUILD_BASE_CONFIG, NO_ASSET_LOADERS, } from '../config/esbuild.js';
|
|
2
|
+
import { DEV_CLIENT_DIR } from '../config/path.js';
|
|
3
|
+
// Create compiler configuration
|
|
4
|
+
export function createClientConfig(env, options) {
|
|
5
|
+
const isDev = env === 'dev';
|
|
6
|
+
// Base config with required properties
|
|
7
|
+
const baseConfig = {
|
|
8
|
+
...ESBUILD_BASE_CONFIG,
|
|
9
|
+
absWorkingDir: options.absWorkingDir,
|
|
10
|
+
entryPoints: options.entryPoints,
|
|
11
|
+
outdir: DEV_CLIENT_DIR,
|
|
12
|
+
plugins: [],
|
|
13
|
+
};
|
|
14
|
+
if (isDev) {
|
|
15
|
+
// Dev configuration
|
|
16
|
+
return {
|
|
17
|
+
...baseConfig,
|
|
18
|
+
platform: 'browser',
|
|
19
|
+
target: ['es2022'],
|
|
20
|
+
loader: {
|
|
21
|
+
...BASE_LOADERS,
|
|
22
|
+
...ASSET_LOADERS,
|
|
23
|
+
},
|
|
24
|
+
bundle: true,
|
|
25
|
+
packages: 'bundle',
|
|
26
|
+
minify: false,
|
|
27
|
+
minifyWhitespace: false,
|
|
28
|
+
minifyIdentifiers: false,
|
|
29
|
+
minifySyntax: false,
|
|
30
|
+
write: false,
|
|
31
|
+
splitting: false,
|
|
32
|
+
metafile: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Prod configuration
|
|
37
|
+
return {
|
|
38
|
+
...baseConfig,
|
|
39
|
+
platform: 'browser',
|
|
40
|
+
target: ['es2022'],
|
|
41
|
+
loader: {
|
|
42
|
+
...BASE_LOADERS,
|
|
43
|
+
...ASSET_LOADERS,
|
|
44
|
+
},
|
|
45
|
+
bundle: true,
|
|
46
|
+
packages: 'bundle',
|
|
47
|
+
minify: true,
|
|
48
|
+
minifyWhitespace: true,
|
|
49
|
+
minifyIdentifiers: true,
|
|
50
|
+
minifySyntax: true,
|
|
51
|
+
write: true,
|
|
52
|
+
splitting: true,
|
|
53
|
+
metafile: false,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Return configuration to create server bundler
|
|
59
|
+
*/
|
|
60
|
+
export function createServerConfig(env, options) {
|
|
61
|
+
const isDev = env === 'dev';
|
|
62
|
+
// Base config with required properties
|
|
63
|
+
const baseConfig = {
|
|
64
|
+
...ESBUILD_BASE_CONFIG,
|
|
65
|
+
absWorkingDir: options.absWorkingDir,
|
|
66
|
+
entryPoints: options.entryPoints,
|
|
67
|
+
outdir: DEV_CLIENT_DIR,
|
|
68
|
+
plugins: [],
|
|
69
|
+
};
|
|
70
|
+
if (isDev) {
|
|
71
|
+
// Dev configuration
|
|
72
|
+
return {
|
|
73
|
+
...baseConfig,
|
|
74
|
+
platform: 'node',
|
|
75
|
+
target: ['node18'],
|
|
76
|
+
loader: {
|
|
77
|
+
...BASE_LOADERS,
|
|
78
|
+
...NO_ASSET_LOADERS,
|
|
79
|
+
},
|
|
80
|
+
bundle: false,
|
|
81
|
+
packages: 'external',
|
|
82
|
+
minify: false,
|
|
83
|
+
minifyWhitespace: false,
|
|
84
|
+
minifyIdentifiers: false,
|
|
85
|
+
minifySyntax: false,
|
|
86
|
+
write: false,
|
|
87
|
+
splitting: false,
|
|
88
|
+
metafile: true,
|
|
89
|
+
external: ['react', 'react-dom'],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Prod configuration
|
|
94
|
+
return {
|
|
95
|
+
...baseConfig,
|
|
96
|
+
platform: 'node',
|
|
97
|
+
target: ['node18'],
|
|
98
|
+
loader: {
|
|
99
|
+
...BASE_LOADERS,
|
|
100
|
+
...NO_ASSET_LOADERS,
|
|
101
|
+
},
|
|
102
|
+
bundle: false,
|
|
103
|
+
packages: 'external',
|
|
104
|
+
minify: true,
|
|
105
|
+
minifyWhitespace: true,
|
|
106
|
+
minifyIdentifiers: true,
|
|
107
|
+
minifySyntax: true,
|
|
108
|
+
write: true,
|
|
109
|
+
splitting: true,
|
|
110
|
+
metafile: false,
|
|
111
|
+
external: ['react', 'react-dom'],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ESBuildConfig } from '../types/config.js';
|
|
2
|
+
export declare const BASE_LOADERS: {
|
|
3
|
+
readonly '.js': "js";
|
|
4
|
+
readonly '.jsx': "jsx";
|
|
5
|
+
readonly '.ts': "ts";
|
|
6
|
+
readonly '.tsx': "tsx";
|
|
7
|
+
readonly '.json': "json";
|
|
8
|
+
};
|
|
9
|
+
export declare const ASSET_LOADERS: {
|
|
10
|
+
readonly '.css': "css";
|
|
11
|
+
readonly '.png': "file";
|
|
12
|
+
readonly '.svg': "file";
|
|
13
|
+
readonly '.jpg': "file";
|
|
14
|
+
readonly '.jpeg': "file";
|
|
15
|
+
readonly '.gif': "file";
|
|
16
|
+
readonly '.webp': "file";
|
|
17
|
+
readonly '.woff': "file";
|
|
18
|
+
readonly '.woff2': "file";
|
|
19
|
+
};
|
|
20
|
+
export declare const NO_ASSET_LOADERS: {
|
|
21
|
+
readonly '.css': "empty";
|
|
22
|
+
readonly '.png': "empty";
|
|
23
|
+
readonly '.svg': "empty";
|
|
24
|
+
readonly '.jpg': "empty";
|
|
25
|
+
readonly '.jpeg': "empty";
|
|
26
|
+
readonly '.gif': "empty";
|
|
27
|
+
readonly '.webp': "empty";
|
|
28
|
+
readonly '.woff': "empty";
|
|
29
|
+
readonly '.woff2': "empty";
|
|
30
|
+
};
|
|
31
|
+
export declare const ESBUILD_BASE_CONFIG: Partial<ESBuildConfig>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Base loader configurations
|
|
2
|
+
export const BASE_LOADERS = {
|
|
3
|
+
'.js': 'js',
|
|
4
|
+
'.jsx': 'jsx',
|
|
5
|
+
'.ts': 'ts',
|
|
6
|
+
'.tsx': 'tsx',
|
|
7
|
+
'.json': 'json',
|
|
8
|
+
};
|
|
9
|
+
export const ASSET_LOADERS = {
|
|
10
|
+
'.css': 'css',
|
|
11
|
+
'.png': 'file',
|
|
12
|
+
'.svg': 'file',
|
|
13
|
+
'.jpg': 'file',
|
|
14
|
+
'.jpeg': 'file',
|
|
15
|
+
'.gif': 'file',
|
|
16
|
+
'.webp': 'file',
|
|
17
|
+
'.woff': 'file',
|
|
18
|
+
'.woff2': 'file',
|
|
19
|
+
};
|
|
20
|
+
export const NO_ASSET_LOADERS = {
|
|
21
|
+
'.css': 'empty',
|
|
22
|
+
'.png': 'empty',
|
|
23
|
+
'.svg': 'empty',
|
|
24
|
+
'.jpg': 'empty',
|
|
25
|
+
'.jpeg': 'empty',
|
|
26
|
+
'.gif': 'empty',
|
|
27
|
+
'.webp': 'empty',
|
|
28
|
+
'.woff': 'empty',
|
|
29
|
+
'.woff2': 'empty',
|
|
30
|
+
};
|
|
31
|
+
// Base configuration
|
|
32
|
+
export const ESBUILD_BASE_CONFIG = {
|
|
33
|
+
// Build optimizations
|
|
34
|
+
metafile: true,
|
|
35
|
+
color: true,
|
|
36
|
+
logLevel: 'silent',
|
|
37
|
+
// Performance
|
|
38
|
+
treeShaking: true,
|
|
39
|
+
// Code splitting
|
|
40
|
+
splitting: false,
|
|
41
|
+
// Format
|
|
42
|
+
format: 'esm',
|
|
43
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param path - The path to normalize
|
|
3
|
+
* @returns Normalized Path
|
|
4
|
+
*/
|
|
5
|
+
export declare const normalizePath: (path: string) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Generates the correct relative path to the static directory based on the current URL depth
|
|
8
|
+
* @param currentPath - The current page URL path
|
|
9
|
+
* @param staticDir - The static directory name (default: "static")
|
|
10
|
+
* @returns The relative path to the static directory
|
|
11
|
+
*/
|
|
12
|
+
export declare function getStaticPath(currentPath: string, staticDir?: string): string;
|
|
13
|
+
export declare const DEV_RUNTIME_DIR: string;
|
|
14
|
+
export declare const DEV_CLIENT_DIR: string;
|
|
15
|
+
export declare const DEV_SERVER_DIR: string;
|
|
16
|
+
export declare const DEV_SERVER_ENTRY: string;
|
|
17
|
+
export declare const DEV_CLIENT_ENTRY: string;
|
|
18
|
+
export declare const DEV_CLIENT_STATIC_DIR: string;
|
|
19
|
+
export declare const DEV_CLIENT_APP_ENTRY: string;
|
|
20
|
+
export declare const DEV_CLIENT_STYLES_ENTRY: string;
|
|
21
|
+
export declare const DEV_CLIENT_HYDRATE_ENTRY: string;
|
|
22
|
+
export declare const DEV_SERVER_RENDERER_ENTRY: string;
|
|
23
|
+
export declare const DEV_SERVER_APP_ENTRY: string;
|
|
24
|
+
export declare const DEV_SERVER_ROUTER_ENTRY: string;
|
|
25
|
+
export declare const DEV_SSR_CACHE_DIR: string;
|
|
26
|
+
export declare const DEV_SSR_TEMP_MODULE_DIR: string;
|
|
27
|
+
export declare const DEV_CLIENT_MANIFEST_PATH: string;
|
|
28
|
+
export declare const DEV_SERVER_MANIFEST_PATH: string;
|
|
29
|
+
export declare const APP_CONFIG_FILE_PATH: string;
|
|
30
|
+
export declare const APP_STYLESHEET_PATH: string;
|
|
31
|
+
export declare const PATH_PATTERNS: {
|
|
32
|
+
STATIC_FILES: RegExp;
|
|
33
|
+
API_ROUTES: RegExp;
|
|
34
|
+
JS_FILES: RegExp;
|
|
35
|
+
CSS_FILES: RegExp;
|
|
36
|
+
ASSET_FILES: RegExp;
|
|
37
|
+
CONFIG_FILES: RegExp;
|
|
38
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param path - The path to normalize
|
|
3
|
+
* @returns Normalized Path
|
|
4
|
+
*/
|
|
5
|
+
export const normalizePath = (path) => '/' + (path || '').replace(/\/+/g, '/').replace(/^\/+|\/+$/g, '');
|
|
6
|
+
/**
|
|
7
|
+
* Generates the correct relative path to the static directory based on the current URL depth
|
|
8
|
+
* @param currentPath - The current page URL path
|
|
9
|
+
* @param staticDir - The static directory name (default: "static")
|
|
10
|
+
* @returns The relative path to the static directory
|
|
11
|
+
*/
|
|
12
|
+
export function getStaticPath(currentPath, staticDir = 'static') {
|
|
13
|
+
// Normalize path: remove leading/trailing slashes
|
|
14
|
+
const segments = currentPath
|
|
15
|
+
.replace(/^\/+|\/+$/g, '')
|
|
16
|
+
.split('/')
|
|
17
|
+
.filter(p => p);
|
|
18
|
+
const depth = segments.length;
|
|
19
|
+
// Build the relative path
|
|
20
|
+
if (depth === 0) {
|
|
21
|
+
// Root level
|
|
22
|
+
return `./${staticDir}`;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// Go up one level for each directory segment
|
|
26
|
+
const upLevels = '../'.repeat(depth);
|
|
27
|
+
return `${upLevels}${staticDir}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Root runtime directories
|
|
31
|
+
export const DEV_RUNTIME_DIR = normalizePath('.nexus');
|
|
32
|
+
export const DEV_CLIENT_DIR = normalizePath('.nexus/client');
|
|
33
|
+
export const DEV_SERVER_DIR = normalizePath('.nexus/server');
|
|
34
|
+
// App Entry Paths
|
|
35
|
+
export const DEV_SERVER_ENTRY = normalizePath('.nexus/server/entry.tsx');
|
|
36
|
+
export const DEV_CLIENT_ENTRY = normalizePath('.nexus/client/entry.tsx');
|
|
37
|
+
// Client build outputs
|
|
38
|
+
export const DEV_CLIENT_STATIC_DIR = normalizePath('.nexus/client/static');
|
|
39
|
+
export const DEV_CLIENT_APP_ENTRY = normalizePath('.nexus/client/hydrate.js');
|
|
40
|
+
export const DEV_CLIENT_STYLES_ENTRY = normalizePath('.nexus/client/styles.css');
|
|
41
|
+
export const DEV_CLIENT_HYDRATE_ENTRY = normalizePath('.nexus/client/hydrate.tsx');
|
|
42
|
+
export const DEV_SERVER_RENDERER_ENTRY = normalizePath('.nexus/server/renderer.tsx');
|
|
43
|
+
// Server build outputs
|
|
44
|
+
export const DEV_SERVER_APP_ENTRY = normalizePath('.nexus/server/App.ssr.js');
|
|
45
|
+
export const DEV_SERVER_ROUTER_ENTRY = normalizePath('.nexus/server/router.js');
|
|
46
|
+
// Runtime + SSR state
|
|
47
|
+
export const DEV_SSR_CACHE_DIR = normalizePath('.nexus/cache');
|
|
48
|
+
export const DEV_SSR_TEMP_MODULE_DIR = normalizePath('.nexus/runtime/modules');
|
|
49
|
+
// Build result manifests
|
|
50
|
+
export const DEV_CLIENT_MANIFEST_PATH = normalizePath('.nexus/client/manifest.json');
|
|
51
|
+
export const DEV_SERVER_MANIFEST_PATH = normalizePath('.nexus/server/manifest.json');
|
|
52
|
+
// App Config paths
|
|
53
|
+
export const APP_CONFIG_FILE_PATH = normalizePath('nexus.config.ts');
|
|
54
|
+
// Server Paths
|
|
55
|
+
export const APP_STYLESHEET_PATH = normalizePath('static/styles.css');
|
|
56
|
+
// Constants for common path patterns
|
|
57
|
+
export const PATH_PATTERNS = {
|
|
58
|
+
// Pattern matchers for routes
|
|
59
|
+
STATIC_FILES: /^\/static\//,
|
|
60
|
+
API_ROUTES: /^\/api\//,
|
|
61
|
+
// File extensions
|
|
62
|
+
JS_FILES: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
|
|
63
|
+
CSS_FILES: /\.(css|scss|sass|less)$/,
|
|
64
|
+
ASSET_FILES: /\.(png|jpg|jpeg|gif|svg|ico|webp|avif|woff|woff2|ttf|eot)$/,
|
|
65
|
+
// Configuration files
|
|
66
|
+
CONFIG_FILES: /\.config\.(js|ts|json)$/,
|
|
67
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types/config.d.ts
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import type { Loader, Plugin } from 'esbuild';
|
|
2
2
|
export interface ESBuildBaseConfig {
|
|
3
|
-
minify: boolean;
|
|
4
|
-
metafile: true;
|
|
5
3
|
color: true;
|
|
6
4
|
logLevel: 'silent';
|
|
7
5
|
treeShaking: true;
|
|
8
|
-
minifyWhitespace: boolean;
|
|
9
|
-
minifyIdentifiers: boolean;
|
|
10
|
-
minifySyntax: boolean;
|
|
11
|
-
splitting: false;
|
|
12
6
|
format: 'esm';
|
|
13
|
-
sourcemap: boolean | 'inline' | 'linked';
|
|
14
7
|
absWorkingDir: string;
|
|
15
8
|
outdir?: string;
|
|
16
9
|
outfile?: string;
|
|
17
|
-
entryPoints: string[]
|
|
18
|
-
write?: boolean;
|
|
10
|
+
entryPoints: string[];
|
|
19
11
|
plugins: Plugin[];
|
|
12
|
+
jsx: 'automatic';
|
|
20
13
|
}
|
|
21
14
|
export type LoaderFiles = Record<string, Loader>;
|
|
22
15
|
export interface ESBuildClientConfig {
|
|
@@ -24,7 +17,7 @@ export interface ESBuildClientConfig {
|
|
|
24
17
|
target: ['es2022'];
|
|
25
18
|
loader: LoaderFiles;
|
|
26
19
|
bundle: true;
|
|
27
|
-
|
|
20
|
+
packages: 'bundle';
|
|
28
21
|
}
|
|
29
22
|
export interface ESBuildServerConfig {
|
|
30
23
|
platform: 'node';
|
|
@@ -32,27 +25,29 @@ export interface ESBuildServerConfig {
|
|
|
32
25
|
loader: LoaderFiles;
|
|
33
26
|
packages: 'external';
|
|
34
27
|
external: string[];
|
|
35
|
-
bundle:
|
|
36
|
-
splitting: false;
|
|
28
|
+
bundle: false;
|
|
37
29
|
}
|
|
38
30
|
export interface ESBuildDevConfig {
|
|
39
31
|
minify: false;
|
|
40
32
|
minifyWhitespace: false;
|
|
41
33
|
minifyIdentifiers: false;
|
|
42
34
|
minifySyntax: false;
|
|
43
|
-
sourcemap: 'inline' | true;
|
|
44
35
|
write: false;
|
|
36
|
+
splitting: false;
|
|
37
|
+
metafile: true;
|
|
45
38
|
}
|
|
46
39
|
export interface ESBuildProdConfig {
|
|
47
40
|
minify: true;
|
|
48
41
|
minifyWhitespace: true;
|
|
49
42
|
minifyIdentifiers: true;
|
|
50
43
|
minifySyntax: true;
|
|
51
|
-
sourcemap: 'linked' | false;
|
|
52
44
|
write: true;
|
|
45
|
+
splitting: true;
|
|
46
|
+
metafile: false;
|
|
53
47
|
}
|
|
54
48
|
export type ESBuildClientDevConfig = ESBuildBaseConfig & ESBuildClientConfig & ESBuildDevConfig;
|
|
55
49
|
export type ESBuildClientProdConfig = ESBuildBaseConfig & ESBuildClientConfig & ESBuildProdConfig;
|
|
56
50
|
export type ESBuildServerDevConfig = ESBuildBaseConfig & ESBuildServerConfig & ESBuildDevConfig;
|
|
57
51
|
export type ESBuildServerProdConfig = ESBuildBaseConfig & ESBuildServerConfig & ESBuildProdConfig;
|
|
58
52
|
export type ESBuildConfig = ESBuildClientDevConfig | ESBuildClientProdConfig | ESBuildServerDevConfig | ESBuildServerProdConfig;
|
|
53
|
+
export type Loaders = Record<string, Loader>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsaf/bundler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Bundler package for rsaf",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"lint": "eslint
|
|
28
|
-
"lint:fix": "eslint
|
|
27
|
+
"lint": "eslint . --max-warnings=0",
|
|
28
|
+
"lint:fix": "eslint . --fix",
|
|
29
29
|
"type-check": "tsc --noEmit",
|
|
30
30
|
"type-check:watch": "tsc --noEmit --watch",
|
|
31
31
|
"build": "pnpm clean && tsc -b",
|