@rws-framework/client 2.13.8 → 2.14.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import
|
|
2
|
+
import fs from 'fs';
|
|
3
3
|
import { processEnvDefines } from '../../cfg/build_steps/vite/_env_defines';
|
|
4
4
|
import { getRWSVitePlugins } from '../../cfg/build_steps/vite/_loaders';
|
|
5
5
|
import { rwsPath } from '@rws-framework/console';
|
|
@@ -7,14 +7,62 @@ import type { RWSViteConfig } from '../../cfg/build_steps/vite/types';
|
|
|
7
7
|
import type { UserConfig } from 'vite'; // Add this import
|
|
8
8
|
import { RWSScssPlugin } from './rws_scss_plugin';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
+
import { ScriptTarget } from 'typescript';
|
|
12
11
|
|
|
12
|
+
interface CompilerOptionsConfig {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
experimentalDecorators: boolean;
|
|
15
|
+
emitDecoratorMetadata: boolean;
|
|
16
|
+
target: 'ES2018' | 'ES2020' | 'ESNext';
|
|
17
|
+
module: 'es2022' | 'ESNext' | 'commonjs';
|
|
18
|
+
moduleResolution: 'node' | 'bundler';
|
|
19
|
+
strict: boolean;
|
|
20
|
+
esModuleInterop: boolean;
|
|
21
|
+
resolveJsonModule: boolean;
|
|
22
|
+
outDir: string;
|
|
23
|
+
strictNullChecks: boolean;
|
|
24
|
+
skipLibCheck: boolean;
|
|
25
|
+
allowSyntheticDefaultImports: boolean;
|
|
26
|
+
sourceMap: boolean;
|
|
27
|
+
declaration: boolean;
|
|
28
|
+
lib: Array<'DOM' | 'ESNext' | 'ES2018' | 'ES2020'>; // add other lib options as needed
|
|
29
|
+
}
|
|
13
30
|
|
|
31
|
+
interface TSConfig {
|
|
32
|
+
compilerOptions: CompilerOptionsConfig;
|
|
33
|
+
paths?: {[key: string]: string[] };
|
|
34
|
+
include?: string[];
|
|
35
|
+
exclude?: string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function logError(error: any) {
|
|
39
|
+
console.error('Vite config error:', {
|
|
40
|
+
message: error.message,
|
|
41
|
+
stack: error.stack,
|
|
42
|
+
cause: error.cause
|
|
43
|
+
});
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function loadTsConfig(tsPath: string): TSConfig | null
|
|
48
|
+
{
|
|
49
|
+
if(!fs.existsSync(tsPath)){
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const tsConfig = JSON.parse(fs.readFileSync(tsPath, 'utf-8'));
|
|
55
|
+
return tsConfig;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
logError(error);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
14
61
|
|
|
15
62
|
export const _DEFAULT_CFG: RWSViteConfig = {
|
|
16
63
|
dev: true,
|
|
17
64
|
entry: path.resolve(rwsPath.findPackageDir(process.cwd()), 'src', 'index.ts'),
|
|
65
|
+
outDir: path.resolve(rwsPath.findPackageDir(process.cwd()), 'dist'),
|
|
18
66
|
tsConfigPath: path.resolve(rwsPath.findPackageDir(process.cwd()), 'tsconfig.json'),
|
|
19
67
|
cssOutputPath: path.resolve(rwsPath.findPackageDir(process.cwd()), 'public', 'css'),
|
|
20
68
|
};
|
|
@@ -28,17 +76,30 @@ export function rwsViteBuilder(config: Partial<RWSViteConfig> = _DEFAULT_CFG, de
|
|
|
28
76
|
config.cssOutputPath = _DEFAULT_CFG.cssOutputPath;
|
|
29
77
|
}
|
|
30
78
|
|
|
79
|
+
if(!config.outDir){
|
|
80
|
+
config.outDir = _DEFAULT_CFG.outDir;
|
|
81
|
+
}
|
|
82
|
+
|
|
31
83
|
const scssPlugin = new RWSScssPlugin({ autoCompile: [], dev: config.dev as boolean });
|
|
32
84
|
|
|
33
85
|
|
|
34
86
|
const theConfig: RWSViteConfig = {..._DEFAULT_CFG, ...config};
|
|
35
87
|
|
|
36
|
-
|
|
88
|
+
const tsConfig: TSConfig | null = loadTsConfig(theConfig.tsConfigPath);
|
|
89
|
+
|
|
90
|
+
if(!tsConfig){
|
|
91
|
+
throw new Error(`File "${theConfig.tsConfigPath}" was not found!`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const pkgDir: string = rwsPath.findPackageDir(process.cwd());
|
|
95
|
+
|
|
96
|
+
const outFileName = theConfig.outFileName || 'client.rws.js';
|
|
97
|
+
|
|
37
98
|
return {
|
|
38
99
|
define: processEnvDefines(theConfig, _DEFAULT_CFG, devDebug),
|
|
39
100
|
plugins: getRWSVitePlugins({
|
|
40
101
|
scssPlugin,
|
|
41
|
-
packageDir:
|
|
102
|
+
packageDir: pkgDir,
|
|
42
103
|
nodeModulesPath: `${rwsPath.findRootWorkspacePath(process.cwd())}/node_modules`,
|
|
43
104
|
tsConfigPath: theConfig.tsConfigPath,
|
|
44
105
|
cssOutputPath: theConfig.cssOutputPath as string,
|
|
@@ -47,11 +108,25 @@ export function rwsViteBuilder(config: Partial<RWSViteConfig> = _DEFAULT_CFG, de
|
|
|
47
108
|
build: {
|
|
48
109
|
minify: !config.dev,
|
|
49
110
|
sourcemap: config.dev,
|
|
50
|
-
outDir:
|
|
111
|
+
outDir: theConfig.outDir,
|
|
112
|
+
emptyOutDir: true,
|
|
113
|
+
copyPublicDir: false,
|
|
51
114
|
rollupOptions: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
115
|
+
output: {
|
|
116
|
+
entryFileNames: outFileName,
|
|
117
|
+
chunkFileNames: [...outFileName.split('.').slice(0, -1), 'chunk', outFileName.split('.').at(-1)].join('.'),
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
lib: {
|
|
121
|
+
entry: theConfig.entry,
|
|
122
|
+
formats: ['es'],
|
|
123
|
+
fileName: () => outFileName
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
esbuild: {
|
|
127
|
+
target: tsConfig?.compilerOptions?.target?.toString().toLowerCase() || ScriptTarget.ES2022.toString().toLowerCase(),
|
|
128
|
+
tsconfigRaw: {
|
|
129
|
+
compilerOptions: tsConfig.compilerOptions
|
|
55
130
|
}
|
|
56
131
|
}
|
|
57
132
|
};
|