@umijs/plugins 4.0.0-beta.5 → 4.0.0-beta.9

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.
Files changed (2) hide show
  1. package/dist/antd.js +161 -3
  2. package/package.json +19 -13
package/dist/antd.js CHANGED
@@ -1,11 +1,169 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@umijs/utils");
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const presets = {
7
+ antd: {
8
+ plugins: [
9
+ 'isSameOrBefore',
10
+ 'isSameOrAfter',
11
+ 'advancedFormat',
12
+ 'customParseFormat',
13
+ 'weekday',
14
+ 'weekYear',
15
+ 'weekOfYear',
16
+ 'isMoment',
17
+ 'localeData',
18
+ 'localizedFormat',
19
+ ],
20
+ replaceMoment: true,
21
+ },
22
+ antdv3: {
23
+ plugins: [
24
+ 'isSameOrBefore',
25
+ 'isSameOrAfter',
26
+ 'advancedFormat',
27
+ 'customParseFormat',
28
+ 'weekday',
29
+ 'weekYear',
30
+ 'weekOfYear',
31
+ 'isMoment',
32
+ 'localeData',
33
+ 'localizedFormat',
34
+ 'badMutable',
35
+ ],
36
+ replaceMoment: true,
37
+ },
38
+ };
39
+ const getConfig = (api) => {
40
+ let { preset = 'antd', plugins, replaceMoment, } = api.userConfig.antdDayjs || {};
41
+ if (preset && presets[preset]) {
42
+ plugins = presets[preset].plugins;
43
+ replaceMoment = presets[preset].replaceMoment;
44
+ }
45
+ if (plugins)
46
+ plugins = plugins;
47
+ if (replaceMoment !== undefined)
48
+ replaceMoment = replaceMoment;
49
+ return {
50
+ plugins,
51
+ replaceMoment,
52
+ };
53
+ };
54
+ const DIR_NAME = 'plugin-antd';
3
55
  exports.default = (api) => {
4
- api;
56
+ const opts = api.userConfig.antd;
57
+ // dayjs (by default)
58
+ const { dayjs = true } = opts;
59
+ api.describe({
60
+ config: {
61
+ schema(Joi) {
62
+ return Joi.object({
63
+ dark: Joi.boolean(),
64
+ compact: Joi.boolean(),
65
+ config: Joi.object(),
66
+ dayjs: Joi.alternatives(Joi.boolean(), Joi.object({
67
+ preset: Joi.string(),
68
+ plugins: Joi.array(),
69
+ replaceMoment: Joi.boolean(),
70
+ })),
71
+ });
72
+ },
73
+ },
74
+ });
5
75
  // antd import
76
+ // TODO: use api.modifyConfig for support with vite
77
+ api.chainWebpack((memo) => {
78
+ function getUserLibDir({ library }) {
79
+ if (
80
+ // @ts-ignore
81
+ (api.pkg.dependencies && api.pkg.dependencies[library]) ||
82
+ // @ts-ignore
83
+ (api.pkg.devDependencies && api.pkg.devDependencies[library]) ||
84
+ // egg project using `clientDependencies` in ali tnpm
85
+ // @ts-ignore
86
+ (api.pkg.clientDependencies && api.pkg.clientDependencies[library])) {
87
+ return (0, utils_1.winPath)((0, path_1.dirname)(
88
+ // 通过 resolve 往上找,可支持 lerna 仓库
89
+ // lerna 仓库如果用 yarn workspace 的依赖不一定在 node_modules,可能被提到根目录,并且没有 link
90
+ utils_1.resolve.sync(`${library}/package.json`, {
91
+ basedir: api.paths.cwd,
92
+ })));
93
+ }
94
+ return null;
95
+ }
96
+ memo.resolve.alias.set('antd', getUserLibDir({ library: 'antd' }) ||
97
+ (0, path_1.dirname)(require.resolve('antd/package.json')));
98
+ if (dayjs !== false) {
99
+ const { replaceMoment } = getConfig(api);
100
+ if (replaceMoment) {
101
+ memo.resolve.alias.set('moment', getUserLibDir({ library: 'dayjs' }) ||
102
+ (0, path_1.dirname)(require.resolve('dayjs/package.json')));
103
+ }
104
+ }
105
+ return memo;
106
+ });
6
107
  // dark mode
7
108
  // compat mode
8
- // dayjs (by default?)
109
+ if ((opts === null || opts === void 0 ? void 0 : opts.dark) || (opts === null || opts === void 0 ? void 0 : opts.compact)) {
110
+ // support dark mode, user use antd 4 by default
111
+ const { getThemeVariables } = require('antd/dist/theme');
112
+ api.modifyDefaultConfig((config) => {
113
+ config.theme = Object.assign(Object.assign({}, getThemeVariables(opts)), config.theme);
114
+ return config;
115
+ });
116
+ }
117
+ if (dayjs !== false) {
118
+ api.onGenerateFiles({
119
+ fn: () => {
120
+ const { plugins } = getConfig(api);
121
+ const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../templates/antd/dayjs.tpl'), 'utf-8');
122
+ api.writeTmpFile({
123
+ path: 'plugin-antd/dayjs.tsx',
124
+ content: utils_1.Mustache.render(runtimeTpl, {
125
+ plugins,
126
+ dayjsPath: (0, path_1.dirname)(require.resolve('dayjs/package.json')),
127
+ dayjsPluginPath: (0, path_1.dirname)(require.resolve('antd-dayjs-webpack-plugin/package.json')),
128
+ }),
129
+ });
130
+ },
131
+ });
132
+ api.addEntryCodeAhead(() => {
133
+ return [`import './${DIR_NAME}/dayjs.tsx'`];
134
+ });
135
+ }
9
136
  // babel-plugin-import
10
- // antd config provider (HOLD, depends on umi)
137
+ api.addExtraBabelPlugins(() => {
138
+ return [
139
+ [
140
+ require.resolve('babel-plugin-import'),
141
+ {
142
+ libraryName: 'antd',
143
+ libraryDirectory: 'es',
144
+ style: true,
145
+ },
146
+ ],
147
+ ];
148
+ });
149
+ // antd config provider
150
+ // TODO: use umi provider
151
+ if (opts === null || opts === void 0 ? void 0 : opts.config) {
152
+ api.onGenerateFiles({
153
+ fn() {
154
+ // runtime.tsx
155
+ const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../templates/antd/runtime.tpl'), 'utf-8');
156
+ api.writeTmpFile({
157
+ path: `${DIR_NAME}/runtime.tsx`,
158
+ content: utils_1.Mustache.render(runtimeTpl, {
159
+ config: JSON.stringify(opts === null || opts === void 0 ? void 0 : opts.config),
160
+ }),
161
+ });
162
+ },
163
+ });
164
+ //TODO:Runtime Plugin
165
+ api.addRuntimePlugin(() => [
166
+ (0, path_1.join)(api.paths.absTmpPath, DIR_NAME, 'runtime.tsx'),
167
+ ]);
168
+ }
11
169
  };
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-beta.5",
3
+ "version": "4.0.0-beta.9",
4
4
  "description": "@umijs/plugins",
5
+ "homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
6
+ "bugs": "https://github.com/umijs/umi-next/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/umijs/umi-next"
10
+ },
11
+ "license": "MIT",
5
12
  "main": "dist/index.js",
6
13
  "types": "dist/index.d.ts",
7
14
  "files": [
@@ -12,20 +19,19 @@
12
19
  "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
13
20
  "dev": "pnpm build -- --watch"
14
21
  },
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/umijs/umi-next"
22
+ "dependencies": {
23
+ "antd": "^4.16.13",
24
+ "antd-dayjs-webpack-plugin": "^1.0.6",
25
+ "babel-plugin-import": "^1.13.3",
26
+ "dayjs": "^1.10.7"
27
+ },
28
+ "devDependencies": {
29
+ "umi": "4.0.0-beta.9"
18
30
  },
19
- "authors": [
20
- "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
21
- ],
22
- "license": "MIT",
23
- "bugs": "https://github.com/umijs/umi-next/issues",
24
- "homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
25
31
  "publishConfig": {
26
32
  "access": "public"
27
33
  },
28
- "devDependencies": {
29
- "umi": "4.0.0-beta.5"
30
- }
34
+ "authors": [
35
+ "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
36
+ ]
31
37
  }