@kmlckj/licos-ai-cli 1.0.16 → 1.0.19
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/lib/__templates__/expo/.licosproj/scripts/prod_build.sh +7 -5
- package/lib/__templates__/expo/client/app.config.ts +87 -76
- package/lib/__templates__/nextjs/next.config.ts +35 -35
- package/lib/__templates__/nextjs/src/server.ts +129 -129
- package/lib/__templates__/nuxt-vue/nuxt.config.ts +180 -152
- package/lib/__templates__/taro/config/index.ts +352 -352
- package/lib/__templates__/vite/server/server.ts +1 -1
- package/lib/__templates__/vite/server/vite.ts +11 -3
- package/lib/__templates__/vite/vite.config.ts +64 -64
- package/package.json +1 -1
|
@@ -1,352 +1,352 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
import tailwindcss from '@tailwindcss/postcss';
|
|
5
|
-
import { UnifiedViteWeappTailwindcssPlugin } from 'weapp-tailwindcss/vite';
|
|
6
|
-
import { defineConfig, type UserConfigExport } from '@tarojs/cli';
|
|
7
|
-
import type { PluginItem } from '@tarojs/taro/types/compile/config/project';
|
|
8
|
-
import dotenv from 'dotenv';
|
|
9
|
-
import devConfig from './dev';
|
|
10
|
-
import prodConfig from './prod';
|
|
11
|
-
import pkg from '../package.json';
|
|
12
|
-
|
|
13
|
-
dotenv.config({ path: path.resolve(__dirname, '../.env.local') });
|
|
14
|
-
|
|
15
|
-
const projectAssetsDir = path.resolve(__dirname, '../assets');
|
|
16
|
-
const assetMimeTypes: Record<string, string> = {
|
|
17
|
-
'.avif': 'image/avif',
|
|
18
|
-
'.css': 'text/css; charset=utf-8',
|
|
19
|
-
'.gif': 'image/gif',
|
|
20
|
-
'.html': 'text/html; charset=utf-8',
|
|
21
|
-
'.ico': 'image/x-icon',
|
|
22
|
-
'.jpg': 'image/jpeg',
|
|
23
|
-
'.jpeg': 'image/jpeg',
|
|
24
|
-
'.js': 'text/javascript; charset=utf-8',
|
|
25
|
-
'.json': 'application/json; charset=utf-8',
|
|
26
|
-
'.mp3': 'audio/mpeg',
|
|
27
|
-
'.mp4': 'video/mp4',
|
|
28
|
-
'.otf': 'font/otf',
|
|
29
|
-
'.png': 'image/png',
|
|
30
|
-
'.svg': 'image/svg+xml',
|
|
31
|
-
'.ttf': 'font/ttf',
|
|
32
|
-
'.txt': 'text/plain; charset=utf-8',
|
|
33
|
-
'.wasm': 'application/wasm',
|
|
34
|
-
'.webm': 'video/webm',
|
|
35
|
-
'.webp': 'image/webp',
|
|
36
|
-
'.woff': 'font/woff',
|
|
37
|
-
'.woff2': 'font/woff2',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const createProjectAssetsStaticPlugin = () => ({
|
|
41
|
-
name: 'licos-project-assets-static',
|
|
42
|
-
configureServer(server) {
|
|
43
|
-
server.middlewares.use('/assets', (req, res, next) => {
|
|
44
|
-
if (!fs.existsSync(projectAssetsDir)) {
|
|
45
|
-
return next();
|
|
46
|
-
}
|
|
47
|
-
const requestPath = (req.url || '')
|
|
48
|
-
.split('?')[0]
|
|
49
|
-
.replace(/^\/assets\/?/, '')
|
|
50
|
-
.replace(/^\/+/, '');
|
|
51
|
-
let decodedPath = '';
|
|
52
|
-
try {
|
|
53
|
-
decodedPath = decodeURIComponent(requestPath);
|
|
54
|
-
} catch {
|
|
55
|
-
return next();
|
|
56
|
-
}
|
|
57
|
-
const filePath = path.resolve(projectAssetsDir, decodedPath);
|
|
58
|
-
if (filePath !== projectAssetsDir && !filePath.startsWith(`${projectAssetsDir}${path.sep}`)) {
|
|
59
|
-
res.statusCode = 403;
|
|
60
|
-
res.end('Forbidden');
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
|
|
64
|
-
return next();
|
|
65
|
-
}
|
|
66
|
-
res.setHeader(
|
|
67
|
-
'Content-Type',
|
|
68
|
-
assetMimeTypes[path.extname(filePath).toLowerCase()] || 'application/octet-stream',
|
|
69
|
-
);
|
|
70
|
-
fs.createReadStream(filePath).pipe(res);
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const normalizePreviewBasePath = (value?: string) => {
|
|
76
|
-
const trimmed = value?.trim();
|
|
77
|
-
if (!trimmed) {
|
|
78
|
-
return '';
|
|
79
|
-
}
|
|
80
|
-
if (trimmed === '/') {
|
|
81
|
-
return '/';
|
|
82
|
-
}
|
|
83
|
-
return `/${trimmed.replace(/^\/+|\/+$/g, '')}/`;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const parsePort = (value?: string) => {
|
|
87
|
-
const port = Number.parseInt(value || '', 10);
|
|
88
|
-
return Number.isInteger(port) && port > 0 ? port : undefined;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const previewBasePath = normalizePreviewBasePath(
|
|
92
|
-
process.env.LICOS_PREVIEW_BASE_PATH ||
|
|
93
|
-
process.env.VITE_BASE_PATH ||
|
|
94
|
-
process.env.BASE_PATH,
|
|
95
|
-
);
|
|
96
|
-
const h5PublicPath = previewBasePath || './';
|
|
97
|
-
|
|
98
|
-
const createPreviewHmrConfig = () => {
|
|
99
|
-
if (!process.env.LICOS_PREVIEW_BASE_PATH) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
const hmr: Record<string, unknown> = {
|
|
103
|
-
overlay: true,
|
|
104
|
-
path: process.env.LICOS_PREVIEW_HMR_PATH || '/hot/vite-hmr',
|
|
105
|
-
timeout: 30000,
|
|
106
|
-
};
|
|
107
|
-
if (process.env.LICOS_PREVIEW_HMR_HOST) {
|
|
108
|
-
hmr.host = process.env.LICOS_PREVIEW_HMR_HOST;
|
|
109
|
-
}
|
|
110
|
-
if (process.env.LICOS_PREVIEW_HMR_PROTOCOL) {
|
|
111
|
-
hmr.protocol = process.env.LICOS_PREVIEW_HMR_PROTOCOL;
|
|
112
|
-
}
|
|
113
|
-
const clientPort = parsePort(process.env.LICOS_PREVIEW_HMR_CLIENT_PORT);
|
|
114
|
-
if (clientPort) {
|
|
115
|
-
hmr.clientPort = clientPort;
|
|
116
|
-
}
|
|
117
|
-
return hmr;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const generateTTProjectConfig = (outputRoot: string) => {
|
|
121
|
-
const config = {
|
|
122
|
-
miniprogramRoot: './',
|
|
123
|
-
projectname: '<%= appName %>',
|
|
124
|
-
appid: process.env.TARO_APP_TT_APPID || '',
|
|
125
|
-
setting: {
|
|
126
|
-
urlCheck: false,
|
|
127
|
-
es6: false,
|
|
128
|
-
postcss: false,
|
|
129
|
-
minified: false,
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
const outputDir = path.resolve(__dirname, '..', outputRoot);
|
|
133
|
-
if (!fs.existsSync(outputDir)) {
|
|
134
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
135
|
-
}
|
|
136
|
-
fs.writeFileSync(
|
|
137
|
-
path.resolve(outputDir, 'project.config.json'),
|
|
138
|
-
JSON.stringify(config, null, 2),
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
|
|
143
|
-
export default defineConfig<'vite'>(async (merge, _env) => {
|
|
144
|
-
const outputRootMap: Record<string, string> = {
|
|
145
|
-
weapp: 'dist',
|
|
146
|
-
tt: 'dist-tt',
|
|
147
|
-
h5: 'dist-web',
|
|
148
|
-
};
|
|
149
|
-
const defaultOutputRoot = outputRootMap[process.env.TARO_ENV || ''] || 'dist';
|
|
150
|
-
const outputRoot = process.env.OUTPUT_ROOT?.trim() || defaultOutputRoot;
|
|
151
|
-
const isH5 = process.env.TARO_ENV === 'h5';
|
|
152
|
-
|
|
153
|
-
const buildMiniCIPluginConfig = () => {
|
|
154
|
-
const hasWeappConfig = !!process.env.TARO_APP_WEAPP_APPID;
|
|
155
|
-
const hasTTConfig = !!process.env.TARO_APP_TT_EMAIL;
|
|
156
|
-
if (!hasWeappConfig && !hasTTConfig) {
|
|
157
|
-
return [];
|
|
158
|
-
}
|
|
159
|
-
const miniCIConfig: Record<string, any> = {
|
|
160
|
-
version: pkg.version,
|
|
161
|
-
desc: pkg.description,
|
|
162
|
-
};
|
|
163
|
-
if (hasWeappConfig) {
|
|
164
|
-
miniCIConfig.weapp = {
|
|
165
|
-
appid: process.env.TARO_APP_WEAPP_APPID,
|
|
166
|
-
privateKeyPath: 'key/private.appid.key',
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
if (hasTTConfig) {
|
|
170
|
-
miniCIConfig.tt = {
|
|
171
|
-
email: process.env.TARO_APP_TT_EMAIL,
|
|
172
|
-
password: process.env.TARO_APP_TT_PASSWORD,
|
|
173
|
-
setting: {
|
|
174
|
-
skipDomainCheck: true,
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
return [['@tarojs/plugin-mini-ci', miniCIConfig]] as PluginItem[];
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const baseConfig: UserConfigExport<'vite'> = {
|
|
182
|
-
projectName: '<%= appName %>',
|
|
183
|
-
date: '2026-1-13',
|
|
184
|
-
alias: {
|
|
185
|
-
'@': path.resolve(__dirname, '..', 'src'),
|
|
186
|
-
},
|
|
187
|
-
designWidth: 750,
|
|
188
|
-
deviceRatio: {
|
|
189
|
-
640: 2.34 / 2,
|
|
190
|
-
750: 1,
|
|
191
|
-
375: 2,
|
|
192
|
-
828: 1.81 / 2,
|
|
193
|
-
},
|
|
194
|
-
sourceRoot: 'src',
|
|
195
|
-
outputRoot,
|
|
196
|
-
plugins: ['@tarojs/plugin-generator', ...buildMiniCIPluginConfig()],
|
|
197
|
-
defineConstants: {
|
|
198
|
-
PROJECT_DOMAIN: JSON.stringify(
|
|
199
|
-
process.env.PROJECT_DOMAIN ||
|
|
200
|
-
process.env.LICOS_PROJECT_DOMAIN_DEFAULT ||
|
|
201
|
-
'',
|
|
202
|
-
),
|
|
203
|
-
LICOS_TARO_ENV: JSON.stringify(process.env.TARO_ENV || ''),
|
|
204
|
-
},
|
|
205
|
-
copy: {
|
|
206
|
-
patterns: [],
|
|
207
|
-
options: {},
|
|
208
|
-
},
|
|
209
|
-
...(process.env.TARO_ENV === 'tt' && {
|
|
210
|
-
tt: {
|
|
211
|
-
appid: process.env.TARO_APP_TT_APPID,
|
|
212
|
-
projectName: '<%= appName %>',
|
|
213
|
-
},
|
|
214
|
-
}),
|
|
215
|
-
jsMinimizer: 'esbuild',
|
|
216
|
-
framework: 'react',
|
|
217
|
-
compiler: {
|
|
218
|
-
type: 'vite',
|
|
219
|
-
vitePlugins: [
|
|
220
|
-
{
|
|
221
|
-
name: 'postcss-config-loader-plugin',
|
|
222
|
-
config(config) {
|
|
223
|
-
// 通过 postcss 配置注册 tailwindcss 插件
|
|
224
|
-
if (typeof config.css?.postcss === 'object') {
|
|
225
|
-
config.css?.postcss.plugins?.unshift(tailwindcss());
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
...(isH5 ? [createProjectAssetsStaticPlugin()] : []),
|
|
230
|
-
{
|
|
231
|
-
name: 'hmr-config-plugin',
|
|
232
|
-
config() {
|
|
233
|
-
const previewHmrConfig = createPreviewHmrConfig();
|
|
234
|
-
if (previewHmrConfig) {
|
|
235
|
-
return {
|
|
236
|
-
server: {
|
|
237
|
-
hmr: previewHmrConfig,
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
if (!process.env.PROJECT_DOMAIN) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
return {
|
|
245
|
-
server: {
|
|
246
|
-
hmr: {
|
|
247
|
-
overlay: true,
|
|
248
|
-
path: '/hot/vite-hmr',
|
|
249
|
-
port: 6000,
|
|
250
|
-
clientPort: 443,
|
|
251
|
-
timeout: 30000,
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
};
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
...(isH5
|
|
258
|
-
? []
|
|
259
|
-
: [
|
|
260
|
-
UnifiedViteWeappTailwindcssPlugin({
|
|
261
|
-
rem2rpx: true,
|
|
262
|
-
cssEntries: [path.resolve(__dirname, '../src/app.css')],
|
|
263
|
-
}),
|
|
264
|
-
]),
|
|
265
|
-
...(process.env.TARO_ENV === 'tt'
|
|
266
|
-
? [
|
|
267
|
-
{
|
|
268
|
-
name: 'generate-tt-project-config',
|
|
269
|
-
closeBundle() {
|
|
270
|
-
generateTTProjectConfig(outputRoot);
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
]
|
|
274
|
-
: []),
|
|
275
|
-
],
|
|
276
|
-
},
|
|
277
|
-
mini: {
|
|
278
|
-
postcss: {
|
|
279
|
-
pxtransform: {
|
|
280
|
-
enable: true,
|
|
281
|
-
config: {},
|
|
282
|
-
},
|
|
283
|
-
cssModules: {
|
|
284
|
-
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
285
|
-
config: {
|
|
286
|
-
namingPattern: 'module', // 转换模式,取值为 global/module
|
|
287
|
-
generateScopedName: '[name]__[local]___[hash:base64:5]',
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
h5: {
|
|
293
|
-
publicPath: h5PublicPath,
|
|
294
|
-
staticDirectory: 'static',
|
|
295
|
-
router: {
|
|
296
|
-
mode: 'hash',
|
|
297
|
-
},
|
|
298
|
-
devServer: {
|
|
299
|
-
port: <%= port %>,
|
|
300
|
-
host: '0.0.0.0',
|
|
301
|
-
open: false,
|
|
302
|
-
proxy: {
|
|
303
|
-
'/api': {
|
|
304
|
-
target: 'http://localhost:<%= serverPort %>',
|
|
305
|
-
changeOrigin: true,
|
|
306
|
-
},
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
|
-
miniCssExtractPluginOption: {
|
|
310
|
-
ignoreOrder: true,
|
|
311
|
-
filename: 'css/[name].[hash].css',
|
|
312
|
-
chunkFilename: 'css/[name].[chunkhash].css',
|
|
313
|
-
},
|
|
314
|
-
postcss: {
|
|
315
|
-
autoprefixer: {
|
|
316
|
-
enable: true,
|
|
317
|
-
config: {},
|
|
318
|
-
},
|
|
319
|
-
pxtransform: {
|
|
320
|
-
enable: true,
|
|
321
|
-
config: {
|
|
322
|
-
platform: 'h5',
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
cssModules: {
|
|
326
|
-
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
327
|
-
config: {
|
|
328
|
-
namingPattern: 'module', // 转换模式,取值为 global/module
|
|
329
|
-
generateScopedName: '[name]__[local]___[hash:base64:5]',
|
|
330
|
-
},
|
|
331
|
-
},
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
rn: {
|
|
335
|
-
appName: '<%= appName %>',
|
|
336
|
-
postcss: {
|
|
337
|
-
cssModules: {
|
|
338
|
-
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
339
|
-
},
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
process.env.BROWSERSLIST_ENV = process.env.NODE_ENV;
|
|
345
|
-
|
|
346
|
-
if (process.env.NODE_ENV === 'development') {
|
|
347
|
-
// 本地开发构建配置(不混淆压缩)
|
|
348
|
-
return merge({}, baseConfig, devConfig);
|
|
349
|
-
}
|
|
350
|
-
// 生产构建配置(默认开启压缩混淆等)
|
|
351
|
-
return merge({}, baseConfig, prodConfig);
|
|
352
|
-
});
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import tailwindcss from '@tailwindcss/postcss';
|
|
5
|
+
import { UnifiedViteWeappTailwindcssPlugin } from 'weapp-tailwindcss/vite';
|
|
6
|
+
import { defineConfig, type UserConfigExport } from '@tarojs/cli';
|
|
7
|
+
import type { PluginItem } from '@tarojs/taro/types/compile/config/project';
|
|
8
|
+
import dotenv from 'dotenv';
|
|
9
|
+
import devConfig from './dev';
|
|
10
|
+
import prodConfig from './prod';
|
|
11
|
+
import pkg from '../package.json';
|
|
12
|
+
|
|
13
|
+
dotenv.config({ path: path.resolve(__dirname, '../.env.local') });
|
|
14
|
+
|
|
15
|
+
const projectAssetsDir = path.resolve(__dirname, '../assets');
|
|
16
|
+
const assetMimeTypes: Record<string, string> = {
|
|
17
|
+
'.avif': 'image/avif',
|
|
18
|
+
'.css': 'text/css; charset=utf-8',
|
|
19
|
+
'.gif': 'image/gif',
|
|
20
|
+
'.html': 'text/html; charset=utf-8',
|
|
21
|
+
'.ico': 'image/x-icon',
|
|
22
|
+
'.jpg': 'image/jpeg',
|
|
23
|
+
'.jpeg': 'image/jpeg',
|
|
24
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
25
|
+
'.json': 'application/json; charset=utf-8',
|
|
26
|
+
'.mp3': 'audio/mpeg',
|
|
27
|
+
'.mp4': 'video/mp4',
|
|
28
|
+
'.otf': 'font/otf',
|
|
29
|
+
'.png': 'image/png',
|
|
30
|
+
'.svg': 'image/svg+xml',
|
|
31
|
+
'.ttf': 'font/ttf',
|
|
32
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
33
|
+
'.wasm': 'application/wasm',
|
|
34
|
+
'.webm': 'video/webm',
|
|
35
|
+
'.webp': 'image/webp',
|
|
36
|
+
'.woff': 'font/woff',
|
|
37
|
+
'.woff2': 'font/woff2',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const createProjectAssetsStaticPlugin = () => ({
|
|
41
|
+
name: 'licos-project-assets-static',
|
|
42
|
+
configureServer(server) {
|
|
43
|
+
server.middlewares.use('/assets', (req, res, next) => {
|
|
44
|
+
if (!fs.existsSync(projectAssetsDir)) {
|
|
45
|
+
return next();
|
|
46
|
+
}
|
|
47
|
+
const requestPath = (req.url || '')
|
|
48
|
+
.split('?')[0]
|
|
49
|
+
.replace(/^\/assets\/?/, '')
|
|
50
|
+
.replace(/^\/+/, '');
|
|
51
|
+
let decodedPath = '';
|
|
52
|
+
try {
|
|
53
|
+
decodedPath = decodeURIComponent(requestPath);
|
|
54
|
+
} catch {
|
|
55
|
+
return next();
|
|
56
|
+
}
|
|
57
|
+
const filePath = path.resolve(projectAssetsDir, decodedPath);
|
|
58
|
+
if (filePath !== projectAssetsDir && !filePath.startsWith(`${projectAssetsDir}${path.sep}`)) {
|
|
59
|
+
res.statusCode = 403;
|
|
60
|
+
res.end('Forbidden');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
|
|
64
|
+
return next();
|
|
65
|
+
}
|
|
66
|
+
res.setHeader(
|
|
67
|
+
'Content-Type',
|
|
68
|
+
assetMimeTypes[path.extname(filePath).toLowerCase()] || 'application/octet-stream',
|
|
69
|
+
);
|
|
70
|
+
fs.createReadStream(filePath).pipe(res);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const normalizePreviewBasePath = (value?: string) => {
|
|
76
|
+
const trimmed = value?.trim();
|
|
77
|
+
if (!trimmed) {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
if (trimmed === '/') {
|
|
81
|
+
return '/';
|
|
82
|
+
}
|
|
83
|
+
return `/${trimmed.replace(/^\/+|\/+$/g, '')}/`;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const parsePort = (value?: string) => {
|
|
87
|
+
const port = Number.parseInt(value || '', 10);
|
|
88
|
+
return Number.isInteger(port) && port > 0 ? port : undefined;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const previewBasePath = normalizePreviewBasePath(
|
|
92
|
+
process.env.LICOS_PREVIEW_BASE_PATH ||
|
|
93
|
+
process.env.VITE_BASE_PATH ||
|
|
94
|
+
process.env.BASE_PATH,
|
|
95
|
+
);
|
|
96
|
+
const h5PublicPath = previewBasePath || './';
|
|
97
|
+
|
|
98
|
+
const createPreviewHmrConfig = () => {
|
|
99
|
+
if (!process.env.LICOS_PREVIEW_BASE_PATH) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const hmr: Record<string, unknown> = {
|
|
103
|
+
overlay: true,
|
|
104
|
+
path: process.env.LICOS_PREVIEW_HMR_PATH || '/hot/vite-hmr',
|
|
105
|
+
timeout: 30000,
|
|
106
|
+
};
|
|
107
|
+
if (process.env.LICOS_PREVIEW_HMR_HOST) {
|
|
108
|
+
hmr.host = process.env.LICOS_PREVIEW_HMR_HOST;
|
|
109
|
+
}
|
|
110
|
+
if (process.env.LICOS_PREVIEW_HMR_PROTOCOL) {
|
|
111
|
+
hmr.protocol = process.env.LICOS_PREVIEW_HMR_PROTOCOL;
|
|
112
|
+
}
|
|
113
|
+
const clientPort = parsePort(process.env.LICOS_PREVIEW_HMR_CLIENT_PORT);
|
|
114
|
+
if (clientPort) {
|
|
115
|
+
hmr.clientPort = clientPort;
|
|
116
|
+
}
|
|
117
|
+
return hmr;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const generateTTProjectConfig = (outputRoot: string) => {
|
|
121
|
+
const config = {
|
|
122
|
+
miniprogramRoot: './',
|
|
123
|
+
projectname: '<%= appName %>',
|
|
124
|
+
appid: process.env.TARO_APP_TT_APPID || '',
|
|
125
|
+
setting: {
|
|
126
|
+
urlCheck: false,
|
|
127
|
+
es6: false,
|
|
128
|
+
postcss: false,
|
|
129
|
+
minified: false,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
const outputDir = path.resolve(__dirname, '..', outputRoot);
|
|
133
|
+
if (!fs.existsSync(outputDir)) {
|
|
134
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
135
|
+
}
|
|
136
|
+
fs.writeFileSync(
|
|
137
|
+
path.resolve(outputDir, 'project.config.json'),
|
|
138
|
+
JSON.stringify(config, null, 2),
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
|
|
143
|
+
export default defineConfig<'vite'>(async (merge, _env) => {
|
|
144
|
+
const outputRootMap: Record<string, string> = {
|
|
145
|
+
weapp: 'dist',
|
|
146
|
+
tt: 'dist-tt',
|
|
147
|
+
h5: 'dist-web',
|
|
148
|
+
};
|
|
149
|
+
const defaultOutputRoot = outputRootMap[process.env.TARO_ENV || ''] || 'dist';
|
|
150
|
+
const outputRoot = process.env.OUTPUT_ROOT?.trim() || defaultOutputRoot;
|
|
151
|
+
const isH5 = process.env.TARO_ENV === 'h5';
|
|
152
|
+
|
|
153
|
+
const buildMiniCIPluginConfig = () => {
|
|
154
|
+
const hasWeappConfig = !!process.env.TARO_APP_WEAPP_APPID;
|
|
155
|
+
const hasTTConfig = !!process.env.TARO_APP_TT_EMAIL;
|
|
156
|
+
if (!hasWeappConfig && !hasTTConfig) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
const miniCIConfig: Record<string, any> = {
|
|
160
|
+
version: pkg.version,
|
|
161
|
+
desc: pkg.description,
|
|
162
|
+
};
|
|
163
|
+
if (hasWeappConfig) {
|
|
164
|
+
miniCIConfig.weapp = {
|
|
165
|
+
appid: process.env.TARO_APP_WEAPP_APPID,
|
|
166
|
+
privateKeyPath: 'key/private.appid.key',
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
if (hasTTConfig) {
|
|
170
|
+
miniCIConfig.tt = {
|
|
171
|
+
email: process.env.TARO_APP_TT_EMAIL,
|
|
172
|
+
password: process.env.TARO_APP_TT_PASSWORD,
|
|
173
|
+
setting: {
|
|
174
|
+
skipDomainCheck: true,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return [['@tarojs/plugin-mini-ci', miniCIConfig]] as PluginItem[];
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const baseConfig: UserConfigExport<'vite'> = {
|
|
182
|
+
projectName: '<%= appName %>',
|
|
183
|
+
date: '2026-1-13',
|
|
184
|
+
alias: {
|
|
185
|
+
'@': path.resolve(__dirname, '..', 'src'),
|
|
186
|
+
},
|
|
187
|
+
designWidth: 750,
|
|
188
|
+
deviceRatio: {
|
|
189
|
+
640: 2.34 / 2,
|
|
190
|
+
750: 1,
|
|
191
|
+
375: 2,
|
|
192
|
+
828: 1.81 / 2,
|
|
193
|
+
},
|
|
194
|
+
sourceRoot: 'src',
|
|
195
|
+
outputRoot,
|
|
196
|
+
plugins: ['@tarojs/plugin-generator', ...buildMiniCIPluginConfig()],
|
|
197
|
+
defineConstants: {
|
|
198
|
+
PROJECT_DOMAIN: JSON.stringify(
|
|
199
|
+
process.env.PROJECT_DOMAIN ||
|
|
200
|
+
process.env.LICOS_PROJECT_DOMAIN_DEFAULT ||
|
|
201
|
+
'',
|
|
202
|
+
),
|
|
203
|
+
LICOS_TARO_ENV: JSON.stringify(process.env.TARO_ENV || ''),
|
|
204
|
+
},
|
|
205
|
+
copy: {
|
|
206
|
+
patterns: [],
|
|
207
|
+
options: {},
|
|
208
|
+
},
|
|
209
|
+
...(process.env.TARO_ENV === 'tt' && {
|
|
210
|
+
tt: {
|
|
211
|
+
appid: process.env.TARO_APP_TT_APPID,
|
|
212
|
+
projectName: '<%= appName %>',
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
jsMinimizer: 'esbuild',
|
|
216
|
+
framework: 'react',
|
|
217
|
+
compiler: {
|
|
218
|
+
type: 'vite',
|
|
219
|
+
vitePlugins: [
|
|
220
|
+
{
|
|
221
|
+
name: 'postcss-config-loader-plugin',
|
|
222
|
+
config(config) {
|
|
223
|
+
// 通过 postcss 配置注册 tailwindcss 插件
|
|
224
|
+
if (typeof config.css?.postcss === 'object') {
|
|
225
|
+
config.css?.postcss.plugins?.unshift(tailwindcss());
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
...(isH5 ? [createProjectAssetsStaticPlugin()] : []),
|
|
230
|
+
{
|
|
231
|
+
name: 'hmr-config-plugin',
|
|
232
|
+
config() {
|
|
233
|
+
const previewHmrConfig = createPreviewHmrConfig();
|
|
234
|
+
if (previewHmrConfig) {
|
|
235
|
+
return {
|
|
236
|
+
server: {
|
|
237
|
+
hmr: previewHmrConfig,
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (!process.env.PROJECT_DOMAIN) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
server: {
|
|
246
|
+
hmr: {
|
|
247
|
+
overlay: true,
|
|
248
|
+
path: '/hot/vite-hmr',
|
|
249
|
+
port: 6000,
|
|
250
|
+
clientPort: 443,
|
|
251
|
+
timeout: 30000,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
...(isH5
|
|
258
|
+
? []
|
|
259
|
+
: [
|
|
260
|
+
UnifiedViteWeappTailwindcssPlugin({
|
|
261
|
+
rem2rpx: true,
|
|
262
|
+
cssEntries: [path.resolve(__dirname, '../src/app.css')],
|
|
263
|
+
}),
|
|
264
|
+
]),
|
|
265
|
+
...(process.env.TARO_ENV === 'tt'
|
|
266
|
+
? [
|
|
267
|
+
{
|
|
268
|
+
name: 'generate-tt-project-config',
|
|
269
|
+
closeBundle() {
|
|
270
|
+
generateTTProjectConfig(outputRoot);
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
]
|
|
274
|
+
: []),
|
|
275
|
+
],
|
|
276
|
+
},
|
|
277
|
+
mini: {
|
|
278
|
+
postcss: {
|
|
279
|
+
pxtransform: {
|
|
280
|
+
enable: true,
|
|
281
|
+
config: {},
|
|
282
|
+
},
|
|
283
|
+
cssModules: {
|
|
284
|
+
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
285
|
+
config: {
|
|
286
|
+
namingPattern: 'module', // 转换模式,取值为 global/module
|
|
287
|
+
generateScopedName: '[name]__[local]___[hash:base64:5]',
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
h5: {
|
|
293
|
+
publicPath: h5PublicPath,
|
|
294
|
+
staticDirectory: 'static',
|
|
295
|
+
router: {
|
|
296
|
+
mode: 'hash',
|
|
297
|
+
},
|
|
298
|
+
devServer: {
|
|
299
|
+
port: <%= port %>,
|
|
300
|
+
host: '0.0.0.0',
|
|
301
|
+
open: false,
|
|
302
|
+
proxy: {
|
|
303
|
+
'/api': {
|
|
304
|
+
target: 'http://localhost:<%= serverPort %>',
|
|
305
|
+
changeOrigin: true,
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
miniCssExtractPluginOption: {
|
|
310
|
+
ignoreOrder: true,
|
|
311
|
+
filename: 'css/[name].[hash].css',
|
|
312
|
+
chunkFilename: 'css/[name].[chunkhash].css',
|
|
313
|
+
},
|
|
314
|
+
postcss: {
|
|
315
|
+
autoprefixer: {
|
|
316
|
+
enable: true,
|
|
317
|
+
config: {},
|
|
318
|
+
},
|
|
319
|
+
pxtransform: {
|
|
320
|
+
enable: true,
|
|
321
|
+
config: {
|
|
322
|
+
platform: 'h5',
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
cssModules: {
|
|
326
|
+
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
327
|
+
config: {
|
|
328
|
+
namingPattern: 'module', // 转换模式,取值为 global/module
|
|
329
|
+
generateScopedName: '[name]__[local]___[hash:base64:5]',
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
rn: {
|
|
335
|
+
appName: '<%= appName %>',
|
|
336
|
+
postcss: {
|
|
337
|
+
cssModules: {
|
|
338
|
+
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
process.env.BROWSERSLIST_ENV = process.env.NODE_ENV;
|
|
345
|
+
|
|
346
|
+
if (process.env.NODE_ENV === 'development') {
|
|
347
|
+
// 本地开发构建配置(不混淆压缩)
|
|
348
|
+
return merge({}, baseConfig, devConfig);
|
|
349
|
+
}
|
|
350
|
+
// 生产构建配置(默认开启压缩混淆等)
|
|
351
|
+
return merge({}, baseConfig, prodConfig);
|
|
352
|
+
});
|