Skip to content

Commit

Permalink
🚧 wip: 更新双目录结构配置
Browse files Browse the repository at this point in the history
仍然存在问题,表现在 ts 类型报错 BySlin/umi-plugin-electron-builder#9
  • Loading branch information
arvinxx committed Feb 18, 2021
1 parent 2216938 commit 329e19f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 30 deletions.
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"--------- ": "",
"clean": "rm -rf dist release .eslintcache ./src/.umi",
"postinstall": "umi generate tmp && electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
"postuninstall": "electron-builder install-app-deps",
"rebuild-deps": "electron-builder install-app-deps"
},
"lint-staged": {
"*.{js,jsx,less,md,json}": [
Expand Down Expand Up @@ -119,12 +120,5 @@
"umi": "^3.3.7",
"umi-plugin-electron-builder": "^1.0.15",
"umi-plugin-tailwindcss": "^2.1.3"
},
"electronWebpack": {
"main": {
"sourceDirectory": "src/main",
"webpackConfig": "config/webpack.main.ts"
},
"renderer": null
}
}
1 change: 0 additions & 1 deletion src/app.ts

This file was deleted.

24 changes: 12 additions & 12 deletions config/config.ts → src/renderer/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { defineConfig } from 'umi';
import ElectronBuilderOpts from './electronBuilderOpts';
import { resolve } from 'path';
import { readJSONSync } from 'fs-extra';
import { srcPath, isDev } from './utils';

import theme from '../src/renderer/theme/theme';

const isDev = process.env.NODE_ENV === 'development';
import theme from '../theme/theme';

const mainWebpackConfig = require('./webpack.main');
// 必须将作为node的依赖,例如 sqlite3、typeORM 等 external 掉
// 否则无法使用
const pkg = readJSONSync(resolve(__dirname, '../package.json'));
const pkg = readJSONSync(resolve(srcPath, '../package.json'));
const deps = pkg.dependencies;
const externals = Object.keys(deps);

Expand All @@ -26,15 +26,15 @@ export default defineConfig({
routes: [
{
path: '/',
component: '@/renderer/layouts/BaseLayout',
component: '@/layouts/BaseLayout',
routes: [
{
path: '/home',
component: '@/renderer/pages/home',
component: '@/pages/home',
},
{
path: '/database',
component: '@/renderer/pages/database',
component: '@/pages/database',
},
],
},
Expand All @@ -52,16 +52,16 @@ export default defineConfig({
},
fastRefresh: {},
electronBuilder: {
mainSrc: '../../main',
routerMode: isDev ? 'hash' : 'browser',
outputDir: 'release',
builderOptions: ElectronBuilderOpts,
externals,
mainWebpackConfig,
},
alias: {
'@/hooks': resolve(__dirname, '../src/renderer/hooks'),
'@/bridge': resolve(__dirname, '../src/renderer/bridge'),
'@/utils': resolve(__dirname, '../src/renderer/utils'),
'@/common': resolve(__dirname, '../src/common'),
theme: resolve(__dirname, '../src/renderer/theme'), // less 全局样式文件
'@/common': resolve(srcPath, './common'),
'@/bridge': resolve(__dirname, '../bridge'),
theme: resolve(__dirname, '../theme'), // less 全局样式文件
},
});
File renamed without changes.
5 changes: 5 additions & 0 deletions src/renderer/config/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { resolve } = require('path');

export const isDev = process.env.NODE_ENV === 'development';

export const srcPath = resolve(__dirname, '../..');
14 changes: 7 additions & 7 deletions config/webpack.main.ts → src/renderer/config/webpack.main.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const path = require('path');
import { srcPath, isDev } from './utils';

const isDev = process.env.NODE_ENV === 'development';
const { resolve } = require('path');

// @ts-ignore
module.exports = (config) => {
config.optimization.noEmitOnErrors = false;
// ts-loader 中只汇报 main 端的 ts 文件
// 从而修复报 Renderer typing 错误问题
config.resolve.alias = {
'@/common': path.resolve(__dirname, '../src/common'),
'@': path.resolve(__dirname, '../src/main'),
'@/common': resolve(srcPath, 'common'),
'@': resolve(srcPath, 'main'),
};

// ts-loader 中只汇报 main 端的 ts 文件
// 从而修复报 Renderer typing 错误问题
config.module.rules[3].use[0].options = {
transpileOnly: isDev,
configFile: path.resolve(__dirname, '../src/main', 'tsconfig.json'),
configFile: resolve(srcPath, 'main', 'tsconfig.json'),
};
// ForkTsCheckerWebpackPlugin 插件在插件队列中的最后
// 所以在正常 dev 和 local 测试环境下,不开启该功能
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@/common": ["../common"],
"@/common/*": ["../common/*"],
"@/*": ["./*"],
"@@/*": ["../.umi/*"]
"@@/*": ["src/.umi/*"]
}
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2971,7 +2971,7 @@
resolved "https://registry.npm.taobao.org/@types/mustache/download/@types/mustache-4.1.0.tgz#b702b1e2879d9ff1f39ac89a4a7784a489aee947"
integrity sha1-twKx4oedn/HzmsiaSneEpImu6Uc=

"@types/node@*", "@types/node@>= 8", "@types/node@^14.14.28":
"@types/node@*", "@types/node@>= 8":
version "14.14.28"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.28.tgz#cade4b64f8438f588951a6b35843ce536853f25b"
integrity sha512-lg55ArB+ZiHHbBBttLpzD07akz0QPrZgUODNakeC09i62dnrywr9mFErHuaPlB6I7z+sEbK+IYmplahvplCj2g==
Expand Down

0 comments on commit 329e19f

Please sign in to comment.