@modern-js/plugin-tailwindcss 1.4.0 → 1.5.0
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 +41 -0
- package/dist/js/modern/cli.js +120 -0
- package/dist/js/modern/design-token/cli/index.js +127 -0
- package/dist/js/modern/design-token/index.js +2 -0
- package/dist/js/modern/design-token/postcss-plugin/index.js +18 -0
- package/dist/js/modern/design-token/runtime/index.js +3 -0
- package/dist/js/modern/design-token/runtime/plugin.js +62 -0
- package/dist/js/modern/index.js +1 -0
- package/dist/js/modern/tailwind.js +43 -0
- package/dist/js/modern/utils.js +34 -0
- package/dist/js/node/cli.js +1 -1
- package/dist/js/node/design-token/cli/index.js +137 -0
- package/dist/js/node/design-token/index.js +30 -0
- package/dist/js/node/design-token/postcss-plugin/index.js +27 -0
- package/dist/js/node/design-token/runtime/index.js +28 -0
- package/dist/js/node/design-token/runtime/plugin.js +86 -0
- package/dist/js/treeshaking/cli.js +135 -0
- package/dist/js/treeshaking/design-token/cli/index.js +106 -0
- package/dist/js/treeshaking/design-token/index.js +2 -0
- package/dist/js/treeshaking/design-token/postcss-plugin/index.js +30 -0
- package/dist/js/treeshaking/design-token/runtime/index.js +3 -0
- package/dist/js/treeshaking/design-token/runtime/plugin.js +62 -0
- package/dist/js/treeshaking/index.js +1 -0
- package/dist/js/treeshaking/tailwind.js +51 -0
- package/dist/js/treeshaking/utils.js +56 -0
- package/dist/types/design-token/cli/index.d.ts +5 -0
- package/dist/types/design-token/index.d.ts +2 -0
- package/dist/types/design-token/postcss-plugin/index.d.ts +12 -0
- package/dist/types/design-token/runtime/index.d.ts +3 -0
- package/dist/types/design-token/runtime/plugin.d.ts +12 -0
- package/package.json +29 -8
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,46 @@
|
|
1
1
|
# @modern-js/plugin-tailwindcss
|
2
2
|
|
3
|
+
## 1.5.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- 79e83ef: chore: merge `@modern-js/plugin-design-token` to `@modern-js/plugin-tailwindcss`
|
8
|
+
|
9
|
+
chore: 合并 `@modern-js/plugin-design-token` 到 `@modern-js/plugin-tailwindcss`
|
10
|
+
|
11
|
+
- 59c941a: chore(runtime): merge `@modern-js/runtime-core` to `@modern-js/runtime`
|
12
|
+
|
13
|
+
chore(runtime): 合并 `@modern-js/runtime-core` 到 `@modern-js/runtime`
|
14
|
+
|
15
|
+
### Patch Changes
|
16
|
+
|
17
|
+
- Updated dependencies [79e83ef]
|
18
|
+
- Updated dependencies [e0cd14a]
|
19
|
+
- Updated dependencies [287ac8b]
|
20
|
+
- Updated dependencies [22f4dca]
|
21
|
+
- Updated dependencies [59c941a]
|
22
|
+
- Updated dependencies [7b9067f]
|
23
|
+
- @modern-js/utils@1.9.0
|
24
|
+
- @modern-js/runtime@1.5.0
|
25
|
+
|
26
|
+
## 1.4.2
|
27
|
+
|
28
|
+
### Patch Changes
|
29
|
+
|
30
|
+
- nothing happen, only bump
|
31
|
+
- Updated dependencies
|
32
|
+
- @modern-js/utils@1.7.11
|
33
|
+
- @modern-js/plugin-design-token@1.0.11
|
34
|
+
|
35
|
+
## 1.4.1
|
36
|
+
|
37
|
+
### Patch Changes
|
38
|
+
|
39
|
+
- b82869d: change package.json exports
|
40
|
+
- Updated dependencies [b82869d]
|
41
|
+
- @modern-js/utils@1.7.10
|
42
|
+
- @modern-js/plugin-design-token@1.0.11
|
43
|
+
|
3
44
|
## 1.4.0
|
4
45
|
|
5
46
|
### Minor Changes
|
@@ -0,0 +1,120 @@
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
|
+
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
|
+
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6
|
+
|
7
|
+
import path from 'path';
|
8
|
+
import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from '@modern-js/utils';
|
9
|
+
import DesignTokenPlugin from "./design-token/cli";
|
10
|
+
import { getTailwindConfig } from "./tailwind";
|
11
|
+
import { template, checkTwinMacroNotExist } from "./utils";
|
12
|
+
const supportCssInJsLibrary = 'styled-components';
|
13
|
+
export const getRandomTwConfigFileName = internalDirectory => {
|
14
|
+
return slash(path.join(internalDirectory, `tailwind.config.${Date.now()}.${nanoid()}.js`));
|
15
|
+
};
|
16
|
+
export default (() => ({
|
17
|
+
name: '@modern-js/plugin-tailwindcss',
|
18
|
+
// support designSystem.supportStyledComponents
|
19
|
+
usePlugins: [DesignTokenPlugin()],
|
20
|
+
setup: async api => {
|
21
|
+
const {
|
22
|
+
appDirectory,
|
23
|
+
internalDirectory
|
24
|
+
} = api.useAppContext();
|
25
|
+
let internalTwConfigPath = ''; // When reinstalling dependencies, most of the time the project will be restarted
|
26
|
+
|
27
|
+
const notHaveTwinMacro = await checkTwinMacroNotExist(appDirectory);
|
28
|
+
return {
|
29
|
+
prepare() {
|
30
|
+
if (notHaveTwinMacro) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
34
|
+
internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
|
35
|
+
const globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, '*.cjs'));
|
36
|
+
const files = globby.sync(globPattern, {
|
37
|
+
absolute: true
|
38
|
+
});
|
39
|
+
|
40
|
+
if (files.length > 0) {
|
41
|
+
fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), 'utf-8');
|
42
|
+
}
|
43
|
+
},
|
44
|
+
|
45
|
+
validateSchema() {
|
46
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-tailwindcss'];
|
47
|
+
},
|
48
|
+
|
49
|
+
config() {
|
50
|
+
return {
|
51
|
+
tools: {
|
52
|
+
// TODO: Add interface about postcss config
|
53
|
+
// TODO: In module project, also is called, but should not be called.
|
54
|
+
postcss: config => {
|
55
|
+
const modernConfig = api.useResolvedConfigContext();
|
56
|
+
const tailwindConfig = getTailwindConfig(modernConfig, {
|
57
|
+
pureConfig: {
|
58
|
+
content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', // about storybook
|
59
|
+
'./storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
|
60
|
+
}
|
61
|
+
});
|
62
|
+
|
63
|
+
if (Array.isArray(config.postcssOptions.plugins)) {
|
64
|
+
config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
|
65
|
+
} else {
|
66
|
+
config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
|
67
|
+
}
|
68
|
+
},
|
69
|
+
|
70
|
+
babel(config) {
|
71
|
+
var _config$plugins;
|
72
|
+
|
73
|
+
if (notHaveTwinMacro) {
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
|
77
|
+
const twinConfig = {
|
78
|
+
twin: {
|
79
|
+
preset: supportCssInJsLibrary,
|
80
|
+
config: internalTwConfigPath
|
81
|
+
}
|
82
|
+
};
|
83
|
+
(_config$plugins = config.plugins) === null || _config$plugins === void 0 ? void 0 : _config$plugins.some(plugin => {
|
84
|
+
if (Array.isArray(plugin) && plugin[0]) {
|
85
|
+
const pluginTarget = plugin[0];
|
86
|
+
let pluginOptions = plugin[1];
|
87
|
+
|
88
|
+
if (typeof pluginTarget === 'string' && // TODO: use babel chain
|
89
|
+
slash(pluginTarget).includes('compiled/babel-plugin-macros')) {
|
90
|
+
if (pluginOptions) {
|
91
|
+
pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
|
92
|
+
} else {
|
93
|
+
plugin.push(twinConfig);
|
94
|
+
}
|
95
|
+
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
return false;
|
101
|
+
});
|
102
|
+
}
|
103
|
+
|
104
|
+
}
|
105
|
+
};
|
106
|
+
},
|
107
|
+
|
108
|
+
moduleTailwindConfig() {
|
109
|
+
const modernConfig = api.useResolvedConfigContext();
|
110
|
+
const tailwindConfig = getTailwindConfig(modernConfig, {
|
111
|
+
pureConfig: {
|
112
|
+
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']
|
113
|
+
}
|
114
|
+
});
|
115
|
+
return require('tailwindcss')(tailwindConfig);
|
116
|
+
}
|
117
|
+
|
118
|
+
};
|
119
|
+
}
|
120
|
+
}));
|
@@ -0,0 +1,127 @@
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
|
+
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
|
+
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6
|
+
|
7
|
+
import { lazyImport, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from '@modern-js/utils';
|
8
|
+
export default (() => ({
|
9
|
+
name: '@modern-js/plugin-design-token',
|
10
|
+
|
11
|
+
setup(api) {
|
12
|
+
let pluginsExportsUtils;
|
13
|
+
const resolveConfig = lazyImport('tailwindcss/resolveConfig', require);
|
14
|
+
const PLUGIN_IDENTIFIER = 'designToken';
|
15
|
+
|
16
|
+
const getDesignTokens = userConfig => {
|
17
|
+
const {
|
18
|
+
source: {
|
19
|
+
designSystem
|
20
|
+
}
|
21
|
+
} = userConfig; // TODO: Type to be filled
|
22
|
+
|
23
|
+
const tailwindcssConfig = {};
|
24
|
+
tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {}; // not use default design token when designToken.defaultTheme is false or theme is false
|
25
|
+
|
26
|
+
if (!designSystem) {
|
27
|
+
tailwindcssConfig.presets = [];
|
28
|
+
} // when only designSystem exist, need remove supportStyledComponents
|
29
|
+
|
30
|
+
|
31
|
+
if (designSystem) {
|
32
|
+
delete tailwindcssConfig.theme.supportStyledComponents;
|
33
|
+
}
|
34
|
+
|
35
|
+
return resolveConfig(tailwindcssConfig).theme || {};
|
36
|
+
};
|
37
|
+
|
38
|
+
return {
|
39
|
+
config() {
|
40
|
+
const appContext = api.useAppContext();
|
41
|
+
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'plugins');
|
42
|
+
return {
|
43
|
+
source: {
|
44
|
+
alias: {
|
45
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
46
|
+
}
|
47
|
+
},
|
48
|
+
tools: {// TODO: support less、scss、css vars
|
49
|
+
// less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
|
50
|
+
// sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
|
51
|
+
// postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
|
52
|
+
}
|
53
|
+
};
|
54
|
+
},
|
55
|
+
|
56
|
+
modifyEntryImports({
|
57
|
+
entrypoint,
|
58
|
+
imports
|
59
|
+
}) {
|
60
|
+
const userConfig = api.useResolvedConfigContext();
|
61
|
+
const {
|
62
|
+
source: {
|
63
|
+
designSystem
|
64
|
+
}
|
65
|
+
} = userConfig;
|
66
|
+
|
67
|
+
if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
|
68
|
+
const designTokens = getDesignTokens(userConfig);
|
69
|
+
imports.push({
|
70
|
+
value: '@modern-js/runtime/plugins',
|
71
|
+
specifiers: [{
|
72
|
+
imported: PLUGIN_IDENTIFIER
|
73
|
+
}],
|
74
|
+
initialize: `
|
75
|
+
const designTokens = ${JSON.stringify(designTokens)};
|
76
|
+
`
|
77
|
+
});
|
78
|
+
}
|
79
|
+
|
80
|
+
return {
|
81
|
+
entrypoint,
|
82
|
+
imports
|
83
|
+
};
|
84
|
+
},
|
85
|
+
|
86
|
+
modifyEntryRuntimePlugins({
|
87
|
+
entrypoint,
|
88
|
+
plugins
|
89
|
+
}) {
|
90
|
+
const {
|
91
|
+
source: {
|
92
|
+
designSystem
|
93
|
+
}
|
94
|
+
} = api.useResolvedConfigContext();
|
95
|
+
let useSCThemeProvider = true;
|
96
|
+
|
97
|
+
if (designSystem) {
|
98
|
+
// when designSystem exist, designToken.styledComponents`s default value is false.
|
99
|
+
useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
|
100
|
+
}
|
101
|
+
|
102
|
+
if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
|
103
|
+
plugins.push({
|
104
|
+
name: PLUGIN_IDENTIFIER,
|
105
|
+
options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? 'true' : 'false'}, useDesignTokenContext: false}`
|
106
|
+
});
|
107
|
+
}
|
108
|
+
|
109
|
+
return {
|
110
|
+
entrypoint,
|
111
|
+
plugins
|
112
|
+
};
|
113
|
+
},
|
114
|
+
|
115
|
+
validateSchema() {
|
116
|
+
// add source.designSystem.supportStyledComponents config
|
117
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
|
118
|
+
},
|
119
|
+
|
120
|
+
addRuntimeExports() {
|
121
|
+
pluginsExportsUtils.addExport(`export { default as designToken } from '@modern-js/plugin-tailwindcss/runtime-design-token'`);
|
122
|
+
}
|
123
|
+
|
124
|
+
};
|
125
|
+
}
|
126
|
+
|
127
|
+
}));
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export default (({
|
2
|
+
cssVarsHash: _cssVarsHash = {}
|
3
|
+
} = {}) => ({
|
4
|
+
postcssPlugin: 'postcss-replace-css-vars',
|
5
|
+
|
6
|
+
Declaration(decl) {
|
7
|
+
if (decl.value && typeof decl.value === 'string') {
|
8
|
+
decl.value = decl.value.replace(/--\S*/g, match => {
|
9
|
+
if (_cssVarsHash[match]) {
|
10
|
+
return _cssVarsHash[match];
|
11
|
+
}
|
12
|
+
|
13
|
+
return match;
|
14
|
+
});
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
}));
|
@@ -0,0 +1,62 @@
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
|
+
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
|
+
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6
|
+
|
7
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
8
|
+
import React, { useContext } from 'react';
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
10
|
+
export const DesignTokenContext = /*#__PURE__*/React.createContext({});
|
11
|
+
export const useDesignTokens = () => useContext(DesignTokenContext);
|
12
|
+
export default ((options = {}) => ({
|
13
|
+
name: '@modern-js/plugin-design-token',
|
14
|
+
setup: () => ({
|
15
|
+
hoc({
|
16
|
+
App
|
17
|
+
}, next) {
|
18
|
+
const DesignTokenAppWrapper = props => {
|
19
|
+
const {
|
20
|
+
token = {},
|
21
|
+
useStyledComponentsThemeProvider = false,
|
22
|
+
useDesignTokenContext = false
|
23
|
+
} = options;
|
24
|
+
|
25
|
+
if (useStyledComponentsThemeProvider && useDesignTokenContext) {
|
26
|
+
const {
|
27
|
+
ThemeProvider
|
28
|
+
} = require('@modern-js/runtime/styled');
|
29
|
+
|
30
|
+
return /*#__PURE__*/_jsx(ThemeProvider, {
|
31
|
+
theme: token,
|
32
|
+
children: /*#__PURE__*/_jsx(DesignTokenContext.Provider, {
|
33
|
+
value: token,
|
34
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
35
|
+
})
|
36
|
+
});
|
37
|
+
} else if (useStyledComponentsThemeProvider) {
|
38
|
+
const {
|
39
|
+
ThemeProvider
|
40
|
+
} = require('@modern-js/runtime/styled');
|
41
|
+
|
42
|
+
return /*#__PURE__*/_jsx(ThemeProvider, {
|
43
|
+
theme: token,
|
44
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
45
|
+
});
|
46
|
+
} else if (useDesignTokenContext) {
|
47
|
+
return /*#__PURE__*/_jsx(DesignTokenContext.Provider, {
|
48
|
+
value: token,
|
49
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
50
|
+
});
|
51
|
+
} else {
|
52
|
+
return /*#__PURE__*/_jsx(App, _objectSpread({}, props));
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
return next({
|
57
|
+
App: hoistNonReactStatics(DesignTokenAppWrapper, App)
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
61
|
+
})
|
62
|
+
}));
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from "./cli";
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { applyOptionsChain, logger } from '@modern-js/utils';
|
2
|
+
import { merge, cloneDeep } from '@modern-js/utils/lodash';
|
3
|
+
|
4
|
+
const checkIfExistNotAllowKeys = tailwindConfig => {
|
5
|
+
const notAllowExistKeys = ['theme'];
|
6
|
+
let notAllowKey = '';
|
7
|
+
const ret = Object.keys(tailwindConfig).some(key => notAllowExistKeys.includes(key) && (notAllowKey = key));
|
8
|
+
return [ret, notAllowKey];
|
9
|
+
};
|
10
|
+
|
11
|
+
const getPureDesignSystemConfig = designSystemConfig => {
|
12
|
+
const pureDesignSystemConfig = cloneDeep(designSystemConfig);
|
13
|
+
delete pureDesignSystemConfig.supportStyledComponents;
|
14
|
+
return pureDesignSystemConfig;
|
15
|
+
};
|
16
|
+
|
17
|
+
const getTailwindConfig = (config, option = {}) => {
|
18
|
+
const purgeConfig = merge({
|
19
|
+
// TODO: how the operating environment is determined
|
20
|
+
enabled: process.env.NODE_ENV === 'production',
|
21
|
+
// TODO: Remove or not
|
22
|
+
layers: ['utilities'],
|
23
|
+
content: []
|
24
|
+
}, option.pureConfig || {});
|
25
|
+
const defaultTailwindConfig = {
|
26
|
+
purge: purgeConfig
|
27
|
+
};
|
28
|
+
const tailwindConfig = applyOptionsChain(defaultTailwindConfig, config.tools.tailwindcss || {});
|
29
|
+
const designSystem = getPureDesignSystemConfig(config.source.designSystem || {});
|
30
|
+
const [exist, key] = checkIfExistNotAllowKeys(tailwindConfig);
|
31
|
+
|
32
|
+
if (exist) {
|
33
|
+
logger.error(`should not exist '${key}' on tools.tailwindcss, please remove it`); // eslint-disable-next-line no-process-exit
|
34
|
+
|
35
|
+
process.exit(0);
|
36
|
+
} // Because there is no default theme configuration
|
37
|
+
|
38
|
+
|
39
|
+
tailwindConfig.theme = designSystem || {};
|
40
|
+
return tailwindConfig;
|
41
|
+
};
|
42
|
+
|
43
|
+
export { getTailwindConfig };
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import { fs } from '@modern-js/utils';
|
3
|
+
export const template = configPath => `
|
4
|
+
function _interopRequireDefault(obj) {
|
5
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
6
|
+
}
|
7
|
+
const modernConfig = _interopRequireDefault(require('${configPath}')).default;
|
8
|
+
|
9
|
+
const theme =
|
10
|
+
modernConfig && modernConfig.source && modernConfig.source.designSystem
|
11
|
+
? modernConfig.source.designSystem
|
12
|
+
: {};
|
13
|
+
const tailwindcss =
|
14
|
+
modernConfig && modernConfig.tools && modernConfig.tools.tailwindcss
|
15
|
+
? modernConfig.tools.tailwindcss
|
16
|
+
: {};
|
17
|
+
|
18
|
+
module.exports = {
|
19
|
+
theme,
|
20
|
+
...tailwindcss,
|
21
|
+
};
|
22
|
+
`;
|
23
|
+
export const checkTwinMacroNotExist = async appDirectory => {
|
24
|
+
const depName = 'twin.macro';
|
25
|
+
const packageJson = (await fs.readJSON(path.join(appDirectory, 'package.json'), {
|
26
|
+
throws: false
|
27
|
+
})) || {};
|
28
|
+
|
29
|
+
if (typeof packageJson.dependencies === 'object' && packageJson.dependencies[depName] || typeof packageJson.devDependencies === 'object' && packageJson.devDependencies[depName]) {
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
|
33
|
+
return true;
|
34
|
+
};
|
package/dist/js/node/cli.js
CHANGED
@@ -9,7 +9,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
|
10
10
|
var _utils = require("@modern-js/utils");
|
11
11
|
|
12
|
-
var _cli = _interopRequireDefault(require("
|
12
|
+
var _cli = _interopRequireDefault(require("./design-token/cli"));
|
13
13
|
|
14
14
|
var _tailwind = require("./tailwind");
|
15
15
|
|
@@ -0,0 +1,137 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _utils = require("@modern-js/utils");
|
9
|
+
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
|
+
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
+
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
15
|
+
|
16
|
+
var _default = () => ({
|
17
|
+
name: '@modern-js/plugin-design-token',
|
18
|
+
|
19
|
+
setup(api) {
|
20
|
+
let pluginsExportsUtils;
|
21
|
+
const resolveConfig = (0, _utils.lazyImport)('tailwindcss/resolveConfig', require);
|
22
|
+
const PLUGIN_IDENTIFIER = 'designToken';
|
23
|
+
|
24
|
+
const getDesignTokens = userConfig => {
|
25
|
+
const {
|
26
|
+
source: {
|
27
|
+
designSystem
|
28
|
+
}
|
29
|
+
} = userConfig; // TODO: Type to be filled
|
30
|
+
|
31
|
+
const tailwindcssConfig = {};
|
32
|
+
tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {}; // not use default design token when designToken.defaultTheme is false or theme is false
|
33
|
+
|
34
|
+
if (!designSystem) {
|
35
|
+
tailwindcssConfig.presets = [];
|
36
|
+
} // when only designSystem exist, need remove supportStyledComponents
|
37
|
+
|
38
|
+
|
39
|
+
if (designSystem) {
|
40
|
+
delete tailwindcssConfig.theme.supportStyledComponents;
|
41
|
+
}
|
42
|
+
|
43
|
+
return resolveConfig(tailwindcssConfig).theme || {};
|
44
|
+
};
|
45
|
+
|
46
|
+
return {
|
47
|
+
config() {
|
48
|
+
const appContext = api.useAppContext();
|
49
|
+
pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'plugins');
|
50
|
+
return {
|
51
|
+
source: {
|
52
|
+
alias: {
|
53
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
54
|
+
}
|
55
|
+
},
|
56
|
+
tools: {// TODO: support less、scss、css vars
|
57
|
+
// less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
|
58
|
+
// sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
|
59
|
+
// postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
|
60
|
+
}
|
61
|
+
};
|
62
|
+
},
|
63
|
+
|
64
|
+
modifyEntryImports({
|
65
|
+
entrypoint,
|
66
|
+
imports
|
67
|
+
}) {
|
68
|
+
const userConfig = api.useResolvedConfigContext();
|
69
|
+
const {
|
70
|
+
source: {
|
71
|
+
designSystem
|
72
|
+
}
|
73
|
+
} = userConfig;
|
74
|
+
|
75
|
+
if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
|
76
|
+
const designTokens = getDesignTokens(userConfig);
|
77
|
+
imports.push({
|
78
|
+
value: '@modern-js/runtime/plugins',
|
79
|
+
specifiers: [{
|
80
|
+
imported: PLUGIN_IDENTIFIER
|
81
|
+
}],
|
82
|
+
initialize: `
|
83
|
+
const designTokens = ${JSON.stringify(designTokens)};
|
84
|
+
`
|
85
|
+
});
|
86
|
+
}
|
87
|
+
|
88
|
+
return {
|
89
|
+
entrypoint,
|
90
|
+
imports
|
91
|
+
};
|
92
|
+
},
|
93
|
+
|
94
|
+
modifyEntryRuntimePlugins({
|
95
|
+
entrypoint,
|
96
|
+
plugins
|
97
|
+
}) {
|
98
|
+
const {
|
99
|
+
source: {
|
100
|
+
designSystem
|
101
|
+
}
|
102
|
+
} = api.useResolvedConfigContext();
|
103
|
+
let useSCThemeProvider = true;
|
104
|
+
|
105
|
+
if (designSystem) {
|
106
|
+
// when designSystem exist, designToken.styledComponents`s default value is false.
|
107
|
+
useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
|
108
|
+
}
|
109
|
+
|
110
|
+
if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
|
111
|
+
plugins.push({
|
112
|
+
name: PLUGIN_IDENTIFIER,
|
113
|
+
options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? 'true' : 'false'}, useDesignTokenContext: false}`
|
114
|
+
});
|
115
|
+
}
|
116
|
+
|
117
|
+
return {
|
118
|
+
entrypoint,
|
119
|
+
plugins
|
120
|
+
};
|
121
|
+
},
|
122
|
+
|
123
|
+
validateSchema() {
|
124
|
+
// add source.designSystem.supportStyledComponents config
|
125
|
+
return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
|
126
|
+
},
|
127
|
+
|
128
|
+
addRuntimeExports() {
|
129
|
+
pluginsExportsUtils.addExport(`export { default as designToken } from '@modern-js/plugin-tailwindcss/runtime-design-token'`);
|
130
|
+
}
|
131
|
+
|
132
|
+
};
|
133
|
+
}
|
134
|
+
|
135
|
+
});
|
136
|
+
|
137
|
+
exports.default = _default;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
var _exportNames = {};
|
7
|
+
Object.defineProperty(exports, "default", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function () {
|
10
|
+
return _runtime.default;
|
11
|
+
}
|
12
|
+
});
|
13
|
+
|
14
|
+
var _runtime = _interopRequireWildcard(require("./runtime"));
|
15
|
+
|
16
|
+
Object.keys(_runtime).forEach(function (key) {
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
19
|
+
if (key in exports && exports[key] === _runtime[key]) return;
|
20
|
+
Object.defineProperty(exports, key, {
|
21
|
+
enumerable: true,
|
22
|
+
get: function () {
|
23
|
+
return _runtime[key];
|
24
|
+
}
|
25
|
+
});
|
26
|
+
});
|
27
|
+
|
28
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
29
|
+
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _default = ({
|
9
|
+
cssVarsHash: _cssVarsHash = {}
|
10
|
+
} = {}) => ({
|
11
|
+
postcssPlugin: 'postcss-replace-css-vars',
|
12
|
+
|
13
|
+
Declaration(decl) {
|
14
|
+
if (decl.value && typeof decl.value === 'string') {
|
15
|
+
decl.value = decl.value.replace(/--\S*/g, match => {
|
16
|
+
if (_cssVarsHash[match]) {
|
17
|
+
return _cssVarsHash[match];
|
18
|
+
}
|
19
|
+
|
20
|
+
return match;
|
21
|
+
});
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
});
|
26
|
+
|
27
|
+
exports.default = _default;
|