对编译后的module alias提供支持

This commit is contained in:
pqcqaq 2024-11-28 12:04:26 +08:00
parent 88df72c589
commit f13e953692
3 changed files with 38 additions and 20 deletions

View File

@ -88,7 +88,7 @@ export function packageJsonContent({
"build:mp": "${cliBinName} build --target mp --mode production",
"build-analyze:mp": "${cliBinName} build --target mp --mode production --analyze",
"build:watch": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run copy-config-json && npm run watch:server",
"watch:server": "node scripts/watchServer.js",
"watch:server": "node --stack-size=65500 scripts/watchServer.js",
"start:web": "${cliBinName} start --target web --mode development --devMode frontend",
"start:web:server": "${cliBinName} start --target web --mode development",
"start:native": "${cliBinName} start --target rn --mode development --devMode frontend",
@ -277,6 +277,7 @@ export function packageJsonContent({
"workbox-webpack-plugin": "^6.4.1",
"chokidar": "^4.0.1",
"nodemon": "^3.1.7",
"module-alias": "^2.2.3",
},
"browserslist": {
"production": [
@ -308,6 +309,9 @@ export function packageJsonContent({
},
"resolutions": {
"readable-stream": "3.6.2"
},
"_moduleAliases": {
"@project": "./lib"
}
}
`;

View File

@ -1,3 +1,4 @@
require('module-alias/register');
const { startup } = require('@xuchangzju/oak-cli/lib/server/start');
const simpleConnector = require('../lib/config/connector').default;
const pwd = process.cwd();

View File

@ -65,7 +65,7 @@ const watcher = chokidar.watch(watchSourcePath, {
return (
file.endsWith('.tsx') ||
file.endsWith('.json') ||
file.endsWith('.xml') ||
file.endsWith('.xml') ||
file.includes('components') ||
file.includes('pages') ||
file.includes('hooks')
@ -93,26 +93,39 @@ watcher.on('ready', () => {
watcher.on('error', (error) => console.log(`Watcher error: ${error}`));
let isProcessing = false;
const onChangeDebounced = _.debounce((path, type) => {
// 控制台清空
console.clear();
console.warn(`File ${path} has been ${type}d`);
const program = ts.createProgram({
rootNames: [path],
options,
projectReferences,
});
const sourceFile = program.getSourceFile(path);
// 只输出单个文件
const emitResult = program.emit(sourceFile);
// 是否成功
const result = emitResult.emitSkipped;
if (result) {
console.error(`Emit failed for ${path}!`);
} else {
console.log(`Emit succeeded. reload service......`);
if (isProcessing) {
return;
}
}, 1000);
isProcessing = true;
try {
// 控制台清空
console.clear();
console.warn(`File ${path} has been ${type}d`);
const program = ts.createProgram({
rootNames: [path],
options,
projectReferences,
});
const sourceFile = program.getSourceFile(path);
// 只输出单个文件
const emitResult = program.emit(sourceFile);
// 是否成功
const result = emitResult.emitSkipped;
if (result) {
console.error(`Emit failed for ${path}!`);
} else {
console.log(`Emit succeeded. reload service......`);
}
} catch (e) {
console.clear()
console.error(e);
// 结束服务
nodemon.emit('quit');
}
isProcessing = false;
}, 200);
watcher
.on('add', (path) => {