发布于 2022-11-10 20:14:56
为了在Nx中运行have,我在project.json中添加了以下目标
"typeorm": {
"executor": "nx:run-commands",
"outputs": [],
"options": {
"command": "TS_NODE_PROJECT=apps/web-api/tsconfig.app.json ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli --config ./apps/web-api/src/database/cli.ts",
"cwd": "."
}
},其中,cli.ts在命令行配置中返回DataSourceOptions。在内部,我为迁移选项配置了以下内容:
migrations: [path.join(__dirname, 'migrations', '*.[tj]s')],
cli: {
migrationsDir: path.join(__dirname, 'migrations')
},我使用以下package.json脚本执行它:
"migration:generate:web-api": "nx typeorm --project=web-api -- migration:generate -n",为了运行迁移,我增加了webpack的配置:
const glob = require('glob');
module.exports = (config, context) => {
if (config.mode === 'production') {
config.optimization = {
minimize: false,
};
const sourcePaths = ['apps/web-api/src/database/migrations/**/*.[tj]s'];
const additionalEntries = sourcePaths
.flatMap((entryPath) => glob.sync(entryPath, { absolute: false }))
.reduce((previous, current) => {
const filename = current.split('src/')[1];
previous[filename] = current;
return previous;
}, {});
config.entry = {
...config.entry,
...additionalEntries,
};
}
return config;
};并将我的build目标配置为将其用于:
"build": {
...
"options": {
...
"webpackConfig": "apps/web-api/webpack.config.js",
}
}https://stackoverflow.com/questions/72042201
复制相似问题