@modern-js/plugin-tailwindcss 2.0.0-beta.2 → 2.0.0-beta.4
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.
- package/CHANGELOG.md +181 -0
- package/dist/js/modern/cli.js +139 -84
- package/dist/js/modern/design-token/cli/index.js +58 -54
- package/dist/js/modern/design-token/global.d.js +0 -0
- package/dist/js/modern/design-token/index.js +5 -2
- package/dist/js/modern/design-token/postcss-plugin/index.js +11 -8
- package/dist/js/modern/design-token/runtime/index.js +4 -1
- package/dist/js/modern/design-token/runtime/plugin.js +41 -29
- package/dist/js/modern/index.js +4 -1
- package/dist/js/modern/modern-app.env.d.js +0 -0
- package/dist/js/modern/tailwind.js +30 -24
- package/dist/js/modern/utils.js +32 -8
- package/dist/js/node/cli.js +159 -95
- package/dist/js/node/design-token/cli/index.js +71 -59
- package/dist/js/node/design-token/global.d.js +0 -0
- package/dist/js/node/design-token/index.js +29 -24
- package/dist/js/node/design-token/postcss-plugin/index.js +28 -13
- package/dist/js/node/design-token/runtime/index.js +31 -22
- package/dist/js/node/design-token/runtime/plugin.js +65 -40
- package/dist/js/node/index.js +27 -11
- package/dist/js/node/modern-app.env.d.js +0 -0
- package/dist/js/node/tailwind.js +49 -30
- package/dist/js/node/utils.js +56 -16
- package/dist/js/treeshaking/cli.js +266 -134
- package/dist/js/treeshaking/design-token/cli/index.js +116 -101
- package/dist/js/treeshaking/design-token/global.d.js +1 -0
- package/dist/js/treeshaking/design-token/index.js +3 -2
- package/dist/js/treeshaking/design-token/postcss-plugin/index.js +17 -26
- package/dist/js/treeshaking/design-token/runtime/index.js +2 -1
- package/dist/js/treeshaking/design-token/runtime/plugin.js +76 -55
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/modern-app.env.d.js +1 -0
- package/dist/js/treeshaking/tailwind.js +86 -43
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/js/treeshaking/utils.js +159 -44
- package/dist/types/cli.d.ts +5 -2
- package/dist/types/design-token/cli/index.d.ts +2 -0
- package/dist/types/design-token/postcss-plugin/index.d.ts +2 -0
- package/dist/types/design-token/runtime/plugin.d.ts +2 -0
- package/dist/types/tailwind.d.ts +3 -3
- package/dist/types/types.d.ts +4 -10
- package/package.json +11 -9
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,186 @@
|
|
1
1
|
# @modern-js/plugin-tailwindcss
|
2
2
|
|
3
|
+
## 2.0.0-beta.4
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- dda38c9c3e: chore: v2
|
8
|
+
|
9
|
+
### Minor Changes
|
10
|
+
|
11
|
+
- 92f0eade39: feat:
|
12
|
+
|
13
|
+
1. add style config and add new hook
|
14
|
+
2. add dts alias logic
|
15
|
+
3. add copy logic
|
16
|
+
4. add log logic
|
17
|
+
5. add skipDeps config
|
18
|
+
|
19
|
+
feat:
|
20
|
+
|
21
|
+
1. 添加样式配置以及新的 hook
|
22
|
+
2. 添加 dts 别名处理
|
23
|
+
3. 添加 copy 逻辑
|
24
|
+
4. 添加日志逻辑
|
25
|
+
5. 添加 skipDeps 配置
|
26
|
+
|
27
|
+
- 92f0eade39: feat:
|
28
|
+
|
29
|
+
1. core: 增加 test 函数
|
30
|
+
2. module plugins: 增加 `babel`, `mainField`, `target` 插件
|
31
|
+
3. storybook: 修改部分逻辑并且增加 tspath webpack 插件
|
32
|
+
4. 增加 designSystem 配置
|
33
|
+
|
34
|
+
feat:
|
35
|
+
|
36
|
+
1. core: add test method
|
37
|
+
2. module plugins: add `babel`, `mainField`, `target` plugin
|
38
|
+
3. storybook: change some logic and add tspath webpack plugin
|
39
|
+
4. add `designSystem` config
|
40
|
+
|
41
|
+
### Patch Changes
|
42
|
+
|
43
|
+
- d6546ad916: add buildConfig style in module-tools and remove tools
|
44
|
+
在 module-tools 里新增 buildConfig style 并删除 tools
|
45
|
+
- 67472ca: fix: move babel-plugin-marcos to plugin-tailwindcss
|
46
|
+
|
47
|
+
fix: 将 babel-plugin-marcos 依赖移动到 plugin-tailwindcss 中
|
48
|
+
|
49
|
+
- Updated dependencies [2344eb26ed]
|
50
|
+
- Updated dependencies [a11fcf8b50]
|
51
|
+
- Updated dependencies [a931594]
|
52
|
+
- Updated dependencies [e7ce063]
|
53
|
+
- Updated dependencies [b18fa8f3ed]
|
54
|
+
- Updated dependencies [7879e8f]
|
55
|
+
- Updated dependencies [50d4675]
|
56
|
+
- Updated dependencies [c9e800d39a]
|
57
|
+
- Updated dependencies [6604f1b]
|
58
|
+
- Updated dependencies [6aca875]
|
59
|
+
- Updated dependencies [fda836f]
|
60
|
+
- Updated dependencies [d6bc321]
|
61
|
+
- Updated dependencies [3e57f2bd58]
|
62
|
+
- Updated dependencies [2e6031955e]
|
63
|
+
- Updated dependencies [c5798d2]
|
64
|
+
- Updated dependencies [fbf5eed5aa]
|
65
|
+
- Updated dependencies [a2509bfbdb]
|
66
|
+
- Updated dependencies [a7c6883]
|
67
|
+
- Updated dependencies [425e57092d]
|
68
|
+
- Updated dependencies [e4357f1856]
|
69
|
+
- Updated dependencies [7b7d12c]
|
70
|
+
- Updated dependencies [4369648ae2]
|
71
|
+
- Updated dependencies [92f0eade39]
|
72
|
+
- Updated dependencies [92c0994468]
|
73
|
+
- Updated dependencies [2cc2eb3]
|
74
|
+
- Updated dependencies [edd1cfb1af]
|
75
|
+
- Updated dependencies [cc971eabfc]
|
76
|
+
- Updated dependencies [5b9049f2e9]
|
77
|
+
- Updated dependencies [6bda14ed71]
|
78
|
+
- Updated dependencies [92004d1906]
|
79
|
+
- Updated dependencies [b8bbe036c7]
|
80
|
+
- Updated dependencies [40ed5874c6]
|
81
|
+
- Updated dependencies [60d5378632]
|
82
|
+
- Updated dependencies [d5a31df781]
|
83
|
+
- Updated dependencies [dda38c9c3e]
|
84
|
+
- Updated dependencies [8b8e1bb571]
|
85
|
+
- Updated dependencies [3bbea92b2a]
|
86
|
+
- Updated dependencies [9144c21]
|
87
|
+
- Updated dependencies [b710adb843]
|
88
|
+
- Updated dependencies [18aaf42249]
|
89
|
+
- Updated dependencies [34702d5]
|
90
|
+
- Updated dependencies [fcace5b5b9]
|
91
|
+
- Updated dependencies [ea7cf06]
|
92
|
+
- Updated dependencies [bbe4c4a]
|
93
|
+
- Updated dependencies [e4558a0]
|
94
|
+
- Updated dependencies [abf3421a75]
|
95
|
+
- Updated dependencies [543be9558e]
|
96
|
+
- Updated dependencies [14b712da84]
|
97
|
+
- @modern-js/runtime@2.0.0-beta.4
|
98
|
+
- @modern-js/utils@2.0.0-beta.4
|
99
|
+
|
100
|
+
## 2.0.0-beta.3
|
101
|
+
|
102
|
+
### Major Changes
|
103
|
+
|
104
|
+
- dda38c9c3e: chore: v2
|
105
|
+
|
106
|
+
### Minor Changes
|
107
|
+
|
108
|
+
- 92f0eade39: feat:
|
109
|
+
|
110
|
+
1. add style config and add new hook
|
111
|
+
2. add dts alias logic
|
112
|
+
3. add copy logic
|
113
|
+
4. add log logic
|
114
|
+
5. add skipDeps config
|
115
|
+
|
116
|
+
feat:
|
117
|
+
|
118
|
+
1. 添加样式配置以及新的 hook
|
119
|
+
2. 添加 dts 别名处理
|
120
|
+
3. 添加 copy 逻辑
|
121
|
+
4. 添加日志逻辑
|
122
|
+
5. 添加 skipDeps 配置
|
123
|
+
|
124
|
+
- 92f0eade39: feat:
|
125
|
+
|
126
|
+
1. core: 增加 test 函数
|
127
|
+
2. module plugins: 增加 `babel`, `mainField`, `target` 插件
|
128
|
+
3. storybook: 修改部分逻辑并且增加 tspath webpack 插件
|
129
|
+
4. 增加 designSystem 配置
|
130
|
+
|
131
|
+
feat:
|
132
|
+
|
133
|
+
1. core: add test method
|
134
|
+
2. module plugins: add `babel`, `mainField`, `target` plugin
|
135
|
+
3. storybook: change some logic and add tspath webpack plugin
|
136
|
+
4. add `designSystem` config
|
137
|
+
|
138
|
+
### Patch Changes
|
139
|
+
|
140
|
+
- d6546ad: add buildConfig style in module-tools-v2 and remove tools
|
141
|
+
在 module-tools-v2 里新增 buildConfig style 并删除 tools
|
142
|
+
- Updated dependencies [2344eb26ed]
|
143
|
+
- Updated dependencies [a11fcf8b50]
|
144
|
+
- Updated dependencies [e7ce063]
|
145
|
+
- Updated dependencies [b18fa8f3ed]
|
146
|
+
- Updated dependencies [c9e800d39a]
|
147
|
+
- Updated dependencies [6604f1b]
|
148
|
+
- Updated dependencies [6aca875]
|
149
|
+
- Updated dependencies [fda836f]
|
150
|
+
- Updated dependencies [3e57f2bd58]
|
151
|
+
- Updated dependencies [2e60319]
|
152
|
+
- Updated dependencies [fbf5eed5aa]
|
153
|
+
- Updated dependencies [a2509bfbdb]
|
154
|
+
- Updated dependencies [425e570]
|
155
|
+
- Updated dependencies [e4357f1]
|
156
|
+
- Updated dependencies [4369648ae2]
|
157
|
+
- Updated dependencies [92f0eade39]
|
158
|
+
- Updated dependencies [92c0994468]
|
159
|
+
- Updated dependencies [edd1cfb1af]
|
160
|
+
- Updated dependencies [cc971eabfc]
|
161
|
+
- Updated dependencies [5b9049f2e9]
|
162
|
+
- Updated dependencies [6bda14ed71]
|
163
|
+
- Updated dependencies [92004d1906]
|
164
|
+
- Updated dependencies [b8bbe036c7]
|
165
|
+
- Updated dependencies [40ed5874c6]
|
166
|
+
- Updated dependencies [60d5378632]
|
167
|
+
- Updated dependencies [d5a31df781]
|
168
|
+
- Updated dependencies [dda38c9c3e]
|
169
|
+
- Updated dependencies [8b8e1bb571]
|
170
|
+
- Updated dependencies [3bbea92b2a]
|
171
|
+
- Updated dependencies [b710adb]
|
172
|
+
- Updated dependencies [18aaf42249]
|
173
|
+
- Updated dependencies [34702d5]
|
174
|
+
- Updated dependencies [fcace5b5b9]
|
175
|
+
- Updated dependencies [ea7cf06]
|
176
|
+
- Updated dependencies [bbe4c4a]
|
177
|
+
- Updated dependencies [e4558a0]
|
178
|
+
- Updated dependencies [abf3421a75]
|
179
|
+
- Updated dependencies [543be9558e]
|
180
|
+
- Updated dependencies [14b712da84]
|
181
|
+
- @modern-js/runtime@2.0.0-beta.3
|
182
|
+
- @modern-js/utils@2.0.0-beta.3
|
183
|
+
|
3
184
|
## 2.0.0-beta.2
|
4
185
|
|
5
186
|
### Major Changes
|
package/dist/js/modern/cli.js
CHANGED
@@ -1,122 +1,177 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
2
|
+
return new Promise((resolve, reject) => {
|
3
|
+
var fulfilled = (value) => {
|
4
|
+
try {
|
5
|
+
step(generator.next(value));
|
6
|
+
} catch (e) {
|
7
|
+
reject(e);
|
8
|
+
}
|
9
|
+
};
|
10
|
+
var rejected = (value) => {
|
11
|
+
try {
|
12
|
+
step(generator.throw(value));
|
13
|
+
} catch (e) {
|
14
|
+
reject(e);
|
15
|
+
}
|
16
|
+
};
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
+
});
|
20
|
+
};
|
21
|
+
import path from "path";
|
22
|
+
import {
|
23
|
+
PLUGIN_SCHEMAS,
|
24
|
+
fs,
|
25
|
+
CONFIG_CACHE_DIR,
|
26
|
+
globby,
|
27
|
+
nanoid,
|
28
|
+
slash
|
29
|
+
} from "@modern-js/utils";
|
6
30
|
import DesignTokenPlugin from "./design-token/cli";
|
7
31
|
import { getTailwindConfig } from "./tailwind";
|
8
32
|
import { template, checkTwinMacroNotExist } from "./utils";
|
9
|
-
const supportCssInJsLibrary =
|
10
|
-
|
11
|
-
return slash(
|
33
|
+
const supportCssInJsLibrary = "styled-components";
|
34
|
+
const getRandomTwConfigFileName = (internalDirectory) => {
|
35
|
+
return slash(
|
36
|
+
path.join(
|
37
|
+
internalDirectory,
|
38
|
+
`tailwind.config.${Date.now()}.${nanoid()}.js`
|
39
|
+
)
|
40
|
+
);
|
12
41
|
};
|
13
|
-
|
14
|
-
pluginName
|
15
|
-
} = {
|
16
|
-
pluginName: '@modern-js/plugin-tailwindcss'
|
42
|
+
var cli_default = ({ pluginName } = {
|
43
|
+
pluginName: "@modern-js/plugin-tailwindcss"
|
17
44
|
}) => ({
|
18
|
-
name:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
let internalTwConfigPath = '';
|
29
|
-
// When reinstalling dependencies, most of the time the project will be restarted
|
30
|
-
const notHaveTwinMacro = await checkTwinMacroNotExist(appDirectory);
|
45
|
+
name: "@modern-js/plugin-tailwindcss",
|
46
|
+
usePlugins: [
|
47
|
+
DesignTokenPlugin({
|
48
|
+
pluginName
|
49
|
+
})
|
50
|
+
],
|
51
|
+
setup: (api) => __async(void 0, null, function* () {
|
52
|
+
const { appDirectory, internalDirectory } = api.useAppContext();
|
53
|
+
let internalTwConfigPath = "";
|
54
|
+
const notHaveTwinMacro = yield checkTwinMacroNotExist(appDirectory);
|
31
55
|
return {
|
32
56
|
prepare() {
|
33
57
|
if (notHaveTwinMacro) {
|
34
58
|
return;
|
35
59
|
}
|
36
60
|
internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
|
37
|
-
const globPattern = slash(
|
61
|
+
const globPattern = slash(
|
62
|
+
path.join(appDirectory, CONFIG_CACHE_DIR, "*.cjs")
|
63
|
+
);
|
38
64
|
const files = globby.sync(globPattern, {
|
39
65
|
absolute: true
|
40
66
|
});
|
41
67
|
if (files.length > 0) {
|
42
|
-
fs.writeFileSync(
|
68
|
+
fs.writeFileSync(
|
69
|
+
internalTwConfigPath,
|
70
|
+
template(files[files.length - 1]),
|
71
|
+
"utf-8"
|
72
|
+
);
|
43
73
|
}
|
44
74
|
},
|
45
75
|
validateSchema() {
|
46
|
-
return PLUGIN_SCHEMAS[
|
76
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-tailwindcss"];
|
47
77
|
},
|
48
78
|
config() {
|
49
79
|
return {
|
50
80
|
tools: {
|
51
|
-
|
52
|
-
|
53
|
-
postcss: config => {
|
81
|
+
postcss: (config) => {
|
82
|
+
var _a, _b;
|
54
83
|
const modernConfig = api.useResolvedConfigContext();
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
const tailwindConfig = getTailwindConfig(modernConfig, {
|
60
|
-
pureConfig: {
|
61
|
-
content: ['./src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', './src/**/*.less', './src/**/*.css', './src/**/*.sass', './src/**/*.scss', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
|
62
|
-
}
|
63
|
-
});
|
64
|
-
config.plugins.push(require('tailwindcss')(tailwindConfig));
|
65
|
-
} else {
|
66
|
-
const tailwindConfig = getTailwindConfig(modernConfig, {
|
67
|
-
pureConfig: {
|
68
|
-
content: ['./src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', './src/**/*.less', './src/**/*.css', './src/**/*.sass', './src/**/*.scss', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
|
69
|
-
}
|
70
|
-
});
|
71
|
-
config.plugins = [require('tailwindcss')(tailwindConfig)];
|
72
|
-
}
|
73
|
-
} else {
|
74
|
-
const tailwindConfig = getTailwindConfig(modernConfig, {
|
84
|
+
const tailwindConfig = getTailwindConfig(
|
85
|
+
(_a = modernConfig == null ? void 0 : modernConfig.tools) == null ? void 0 : _a.tailwindcss,
|
86
|
+
(_b = modernConfig == null ? void 0 : modernConfig.source) == null ? void 0 : _b.designSystem,
|
87
|
+
{
|
75
88
|
pureConfig: {
|
76
|
-
content: [
|
77
|
-
|
78
|
-
|
89
|
+
content: [
|
90
|
+
"./config/html/**/*.html",
|
91
|
+
"./config/html/**/*.ejs",
|
92
|
+
"./config/html/**/*.hbs",
|
93
|
+
"./src/**/*.js",
|
94
|
+
"./src/**/*.jsx",
|
95
|
+
"./src/**/*.ts",
|
96
|
+
"./src/**/*.tsx",
|
97
|
+
"./storybook/**/*",
|
98
|
+
"./styles/**/*.less",
|
99
|
+
"./styles/**/*.css",
|
100
|
+
"./styles/**/*.sass",
|
101
|
+
"./styles/**/*.scss"
|
102
|
+
]
|
79
103
|
}
|
80
|
-
});
|
81
|
-
if (Array.isArray(config.postcssOptions.plugins)) {
|
82
|
-
config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
|
83
|
-
} else {
|
84
|
-
config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
|
85
104
|
}
|
105
|
+
);
|
106
|
+
if (Array.isArray(config.postcssOptions.plugins)) {
|
107
|
+
config.postcssOptions.plugins.push(
|
108
|
+
require("tailwindcss")(tailwindConfig)
|
109
|
+
);
|
110
|
+
} else {
|
111
|
+
config.postcssOptions.plugins = [
|
112
|
+
require("tailwindcss")(tailwindConfig)
|
113
|
+
];
|
86
114
|
}
|
87
115
|
},
|
88
|
-
babel(
|
89
|
-
var _config$plugins;
|
116
|
+
babel(_, { addPlugins }) {
|
90
117
|
if (notHaveTwinMacro) {
|
91
118
|
return;
|
92
119
|
}
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
if (Array.isArray(plugin) && plugin[0]) {
|
101
|
-
const pluginTarget = plugin[0];
|
102
|
-
let pluginOptions = plugin[1];
|
103
|
-
if (typeof pluginTarget === 'string' &&
|
104
|
-
// TODO: use babel chain
|
105
|
-
slash(pluginTarget).includes('compiled/babel-plugin-macros')) {
|
106
|
-
if (pluginOptions) {
|
107
|
-
pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
|
108
|
-
} else {
|
109
|
-
plugin.push(twinConfig);
|
120
|
+
addPlugins([
|
121
|
+
[
|
122
|
+
require.resolve("babel-plugin-macros"),
|
123
|
+
{
|
124
|
+
twin: {
|
125
|
+
preset: supportCssInJsLibrary,
|
126
|
+
config: internalTwConfigPath
|
110
127
|
}
|
111
|
-
return true;
|
112
128
|
}
|
113
|
-
|
114
|
-
|
115
|
-
});
|
129
|
+
]
|
130
|
+
]);
|
116
131
|
}
|
117
132
|
}
|
118
133
|
};
|
134
|
+
},
|
135
|
+
beforeBuildTask({ config }) {
|
136
|
+
const modernConfig = api.useResolvedConfigContext();
|
137
|
+
const { designSystem } = modernConfig;
|
138
|
+
const tailwindConfig = getTailwindConfig(
|
139
|
+
config.style.tailwindCss,
|
140
|
+
designSystem,
|
141
|
+
{
|
142
|
+
pureConfig: {
|
143
|
+
content: [
|
144
|
+
"./config/html/**/*.html",
|
145
|
+
"./config/html/**/*.ejs",
|
146
|
+
"./config/html/**/*.hbs",
|
147
|
+
"./src/**/*.js",
|
148
|
+
"./src/**/*.jsx",
|
149
|
+
"./src/**/*.ts",
|
150
|
+
"./src/**/*.tsx",
|
151
|
+
"./storybook/**/*",
|
152
|
+
"./styles/**/*.less",
|
153
|
+
"./styles/**/*.css",
|
154
|
+
"./styles/**/*.sass",
|
155
|
+
"./styles/**/*.scss"
|
156
|
+
]
|
157
|
+
}
|
158
|
+
}
|
159
|
+
);
|
160
|
+
if (Array.isArray(config.style.postcss.plugins)) {
|
161
|
+
config.style.postcss.plugins.push(
|
162
|
+
require("tailwindcss")(tailwindConfig)
|
163
|
+
);
|
164
|
+
} else {
|
165
|
+
config.style.postcss.plugins = [
|
166
|
+
require("tailwindcss")(tailwindConfig)
|
167
|
+
];
|
168
|
+
}
|
169
|
+
return config;
|
119
170
|
}
|
120
171
|
};
|
121
|
-
}
|
122
|
-
})
|
172
|
+
})
|
173
|
+
});
|
174
|
+
export {
|
175
|
+
cli_default as default,
|
176
|
+
getRandomTwConfigFileName
|
177
|
+
};
|
@@ -1,29 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
6
|
+
var __spreadValues = (a, b) => {
|
7
|
+
for (var prop in b || (b = {}))
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
10
|
+
if (__getOwnPropSymbols)
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
12
|
+
if (__propIsEnum.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
}
|
15
|
+
return a;
|
16
|
+
};
|
17
|
+
import {
|
18
|
+
lazyImport,
|
19
|
+
PLUGIN_SCHEMAS,
|
20
|
+
createRuntimeExportsUtils
|
21
|
+
} from "@modern-js/utils";
|
22
|
+
var cli_default = ({ pluginName } = { pluginName: "@modern-js/plugin-tailwindcss" }) => ({
|
23
|
+
name: "@modern-js/plugin-design-token",
|
11
24
|
setup(api) {
|
12
25
|
let pluginsExportsUtils;
|
13
|
-
const resolveConfig = lazyImport(
|
14
|
-
const PLUGIN_IDENTIFIER =
|
15
|
-
const getDesignTokens =
|
16
|
-
var _userConfig$source;
|
17
|
-
const designSystem = (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.designSystem;
|
26
|
+
const resolveConfig = lazyImport("tailwindcss/resolveConfig", require);
|
27
|
+
const PLUGIN_IDENTIFIER = "designToken";
|
28
|
+
const getDesignTokens = (designSystem) => {
|
18
29
|
const tailwindcssConfig = {};
|
19
|
-
tailwindcssConfig.theme = designSystem ?
|
20
|
-
|
21
|
-
// not use default design token when designToken.defaultTheme is false or theme is false
|
30
|
+
tailwindcssConfig.theme = designSystem ? __spreadValues({}, designSystem) : {};
|
22
31
|
if (!designSystem) {
|
23
32
|
tailwindcssConfig.presets = [];
|
24
33
|
}
|
25
|
-
|
26
|
-
// when only designSystem exist, need remove supportStyledComponents
|
27
34
|
if (designSystem) {
|
28
35
|
delete tailwindcssConfig.theme.supportStyledComponents;
|
29
36
|
}
|
@@ -32,35 +39,32 @@ export default (({
|
|
32
39
|
return {
|
33
40
|
config() {
|
34
41
|
const appContext = api.useAppContext();
|
35
|
-
pluginsExportsUtils = createRuntimeExportsUtils(
|
42
|
+
pluginsExportsUtils = createRuntimeExportsUtils(
|
43
|
+
appContext.internalDirectory,
|
44
|
+
"plugins"
|
45
|
+
);
|
36
46
|
return {
|
37
47
|
source: {
|
38
48
|
alias: {
|
39
|
-
|
49
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
|
40
50
|
}
|
41
51
|
},
|
42
|
-
tools: {
|
43
|
-
// TODO: support less、scss、css vars
|
44
|
-
// less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
|
45
|
-
// sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
|
46
|
-
// postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
|
47
|
-
}
|
52
|
+
tools: {}
|
48
53
|
};
|
49
54
|
},
|
50
|
-
modifyEntryImports({
|
51
|
-
|
52
|
-
imports
|
53
|
-
}) {
|
54
|
-
var _userConfig$source$de, _userConfig$source2;
|
55
|
+
modifyEntryImports({ entrypoint, imports }) {
|
56
|
+
var _a, _b;
|
55
57
|
const userConfig = api.useResolvedConfigContext();
|
56
|
-
const designSystem = (
|
57
|
-
if (typeof designSystem ===
|
58
|
-
const designTokens = getDesignTokens(userConfig);
|
58
|
+
const designSystem = (_b = (_a = userConfig.source) == null ? void 0 : _a.designSystem) != null ? _b : {};
|
59
|
+
if (typeof designSystem === "object" && designSystem.supportStyledComponents) {
|
60
|
+
const designTokens = getDesignTokens(userConfig.source.designSystem);
|
59
61
|
imports.push({
|
60
|
-
value:
|
61
|
-
specifiers: [
|
62
|
-
|
63
|
-
|
62
|
+
value: "@modern-js/runtime/plugins",
|
63
|
+
specifiers: [
|
64
|
+
{
|
65
|
+
imported: PLUGIN_IDENTIFIER
|
66
|
+
}
|
67
|
+
],
|
64
68
|
initialize: `
|
65
69
|
const designTokens = ${JSON.stringify(designTokens)};
|
66
70
|
`
|
@@ -71,22 +75,18 @@ export default (({
|
|
71
75
|
imports
|
72
76
|
};
|
73
77
|
},
|
74
|
-
modifyEntryRuntimePlugins({
|
75
|
-
|
76
|
-
plugins
|
77
|
-
}) {
|
78
|
-
var _userConfig$source$de2, _userConfig$source3;
|
78
|
+
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
79
|
+
var _a, _b;
|
79
80
|
const userConfig = api.useResolvedConfigContext();
|
80
|
-
const designSystem = (
|
81
|
+
const designSystem = (_b = (_a = userConfig.source) == null ? void 0 : _a.designSystem) != null ? _b : {};
|
81
82
|
let useSCThemeProvider = true;
|
82
83
|
if (designSystem) {
|
83
|
-
|
84
|
-
useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
|
84
|
+
useSCThemeProvider = (designSystem == null ? void 0 : designSystem.supportStyledComponents) || false;
|
85
85
|
}
|
86
|
-
if (typeof designSystem ===
|
86
|
+
if (typeof designSystem === "object" && designSystem.supportStyledComponents) {
|
87
87
|
plugins.push({
|
88
88
|
name: PLUGIN_IDENTIFIER,
|
89
|
-
options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ?
|
89
|
+
options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? "true" : "false"}, useDesignTokenContext: false}`
|
90
90
|
});
|
91
91
|
}
|
92
92
|
return {
|
@@ -95,12 +95,16 @@ export default (({
|
|
95
95
|
};
|
96
96
|
},
|
97
97
|
validateSchema() {
|
98
|
-
|
99
|
-
return PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
|
98
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-design-token"];
|
100
99
|
},
|
101
100
|
addRuntimeExports() {
|
102
|
-
pluginsExportsUtils.addExport(
|
101
|
+
pluginsExportsUtils.addExport(
|
102
|
+
`export { default as designToken } from '${pluginName}/runtime-design-token'`
|
103
|
+
);
|
103
104
|
}
|
104
105
|
};
|
105
106
|
}
|
106
|
-
})
|
107
|
+
});
|
108
|
+
export {
|
109
|
+
cli_default as default
|
110
|
+
};
|
File without changes
|
@@ -1,15 +1,18 @@
|
|
1
|
-
|
2
|
-
cssVarsHash
|
1
|
+
var postcss_plugin_default = ({
|
2
|
+
cssVarsHash = {}
|
3
3
|
} = {}) => ({
|
4
|
-
postcssPlugin:
|
4
|
+
postcssPlugin: "postcss-replace-css-vars",
|
5
5
|
Declaration(decl) {
|
6
|
-
if (decl.value && typeof decl.value ===
|
7
|
-
decl.value = decl.value.replace(/--\S*/g, match => {
|
8
|
-
if (
|
9
|
-
return
|
6
|
+
if (decl.value && typeof decl.value === "string") {
|
7
|
+
decl.value = decl.value.replace(/--\S*/g, (match) => {
|
8
|
+
if (cssVarsHash[match]) {
|
9
|
+
return cssVarsHash[match];
|
10
10
|
}
|
11
11
|
return match;
|
12
12
|
});
|
13
13
|
}
|
14
14
|
}
|
15
|
-
})
|
15
|
+
});
|
16
|
+
export {
|
17
|
+
postcss_plugin_default as default
|
18
|
+
};
|