Skip to content

Commit

Permalink
🔖 ⬆️ 🔨 Migrate to antd-pro@2.1
Browse files Browse the repository at this point in the history
🔖 ⬆️ 🔨 Migrate to antd-pro@2.1
  • Loading branch information
xiaohuoni authored Nov 28, 2018
2 parents 8de2ddd + 8ba3728 commit 5ebf311
Show file tree
Hide file tree
Showing 336 changed files with 16,663 additions and 4,443 deletions.
3,449 changes: 3,449 additions & 0 deletions .temp/ant-design-pro.less

Large diffs are not rendered by default.

56 changes: 0 additions & 56 deletions .umirc.js

This file was deleted.

131 changes: 131 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// https://umijs.org/config/
import os from 'os';
import pageRoutes from './router.config';
import webpackPlugin from './plugin.config';
import defaultSettings from '../src/defaultSettings';

const plugins = [
[
'umi-plugin-react',
{
antd: true,
dva: {
hmr: true,
},
targets: {
ie: 11,
},
locale: {
enable: true, // default false
default: 'zh-CN', // default zh-CN
baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
},
routes: {
update(routes) {
return [...require("../src/pages/_routes"), ...routes];
}
},
dynamicImport: {
loadingComponent: './components/PageLoading/index',
},
pwa: {
workboxPluginMode: 'InjectManifest',
workboxOptions: {
importWorkboxFrom: 'local',
},
},
...(!process.env.TEST && os.platform() === 'darwin'
? {
dll: {
include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
exclude: ['@babel/runtime'],
},
hardSource: true,
}
: {}),
},
],
[
"umi-plugin-authorize",
{
authorize: [
{
guard: ["./src/pages/Authorized"],
include: /\//,
exclude: /\/User/
}
]
}
]
];

// 针对 preview.pro.ant.design 的 GA 统计代码
// 业务上不需要这个
if (process.env.APP_TYPE === 'site') {
plugins.push([
'umi-plugin-ga',
{
code: 'UA-72788897-6',
},
]);
}

export default {
// add for transfer to umi
plugins,
targets: {
ie: 11,
},
define: {
APP_TYPE: process.env.APP_TYPE || '',
},
// 路由配置
// routes: pageRoutes,
// Theme for antd
// https://ant.design/docs/react/customize-theme-cn
theme: {
'primary-color': defaultSettings.primaryColor,
},
externals: {
'@antv/data-set': 'DataSet',
},
// proxy: {
// '/server/api/': {
// target: 'https://preview.pro.ant.design/',
// changeOrigin: true,
// pathRewrite: { '^/server': '' },
// },
// },
ignoreMomentLocale: true,
lessLoaderOptions: {
javascriptEnabled: true,
},
disableRedirectHoist: true,
cssLoaderOptions: {
modules: true,
getLocalIdent: (context, localIdentName, localName) => {
if (
context.resourcePath.includes('node_modules') ||
context.resourcePath.includes('ant.design.pro.less') ||
context.resourcePath.includes('global.less')
) {
return localName;
}
const match = context.resourcePath.match(/src(.*)/);
if (match && match[1]) {
const antdProPath = match[1].replace('.less', '');
const arr = antdProPath
.split('/')
.map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
}
return localName;
},
},
manifest: {
basePath: '/',
},

chainWebpack: webpackPlugin,
};
33 changes: 33 additions & 0 deletions config/plugin.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Change theme plugin

import MergeLessPlugin from 'antd-pro-merge-less';
import AntDesignThemePlugin from 'antd-theme-webpack-plugin';
import path from 'path';

export default config => {
// pro 和 开发环境再添加这个插件
if (process.env.APP_TYPE === 'site' || process.env.NODE_ENV !== 'production') {
// 将所有 less 合并为一个供 themePlugin使用
const outFile = path.join(__dirname, '../.temp/ant-design-pro.less');
const stylesDir = path.join(__dirname, '../src/');

config.plugin('merge-less').use(MergeLessPlugin, [
{
stylesDir,
outFile,
},
]);

config.plugin('ant-design-theme').use(AntDesignThemePlugin, [
{
antDir: path.join(__dirname, '../node_modules/antd'),
stylesDir,
varFile: path.join(__dirname, '../node_modules/antd/lib/style/themes/default.less'),
mainLessFile: outFile, // themeVariables: ['@primary-color'],
indexFileName: 'index.html',
generateOne: true,
lessUrl: 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js',
},
]);
}
};
Loading

0 comments on commit 5ebf311

Please sign in to comment.