@modern-js/plugin-tailwindcss 2.0.0-beta.0 → 2.0.0-beta.1
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 +70 -0
- package/dist/js/modern/cli.js +33 -37
- package/dist/js/modern/design-token/cli/index.js +13 -38
- package/dist/js/modern/design-token/postcss-plugin/index.js +0 -3
- package/dist/js/modern/design-token/runtime/plugin.js +0 -8
- package/dist/js/modern/tailwind.js +6 -10
- package/dist/js/modern/types.js +0 -0
- package/dist/js/modern/utils.js +0 -2
- package/dist/js/node/cli.js +33 -49
- package/dist/js/node/design-token/cli/index.js +13 -41
- package/dist/js/node/design-token/index.js +0 -4
- package/dist/js/node/design-token/postcss-plugin/index.js +0 -5
- package/dist/js/node/design-token/runtime/index.js +0 -5
- package/dist/js/node/design-token/runtime/plugin.js +0 -20
- package/dist/js/node/index.js +0 -2
- package/dist/js/node/tailwind.js +6 -13
- package/dist/js/node/types.js +0 -0
- package/dist/js/node/utils.js +0 -9
- package/dist/js/treeshaking/cli.js +34 -36
- package/dist/js/treeshaking/design-token/cli/index.js +22 -30
- package/dist/js/treeshaking/design-token/postcss-plugin/index.js +2 -6
- package/dist/js/treeshaking/design-token/runtime/plugin.js +7 -12
- package/dist/js/treeshaking/tailwind.js +9 -14
- package/dist/js/treeshaking/types.js +0 -0
- package/dist/js/treeshaking/utils.js +0 -9
- package/dist/types/cli.d.ts +0 -2
- package/dist/types/design-token/cli/index.d.ts +0 -2
- package/dist/types/design-token/postcss-plugin/index.d.ts +0 -2
- package/dist/types/design-token/runtime/plugin.d.ts +0 -2
- package/dist/types/types.d.ts +10 -0
- package/package.json +9 -9
@@ -4,49 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
|
8
7
|
var _utils = require("@modern-js/utils");
|
9
|
-
|
10
8
|
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
9
|
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
10
|
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
11
|
var _default = ({
|
17
12
|
pluginName
|
18
13
|
} = {
|
19
14
|
pluginName: '@modern-js/plugin-tailwindcss'
|
20
15
|
}) => ({
|
21
16
|
name: '@modern-js/plugin-design-token',
|
22
|
-
|
23
17
|
setup(api) {
|
24
18
|
let pluginsExportsUtils;
|
25
19
|
const resolveConfig = (0, _utils.lazyImport)('tailwindcss/resolveConfig', require);
|
26
20
|
const PLUGIN_IDENTIFIER = 'designToken';
|
27
|
-
|
28
21
|
const getDesignTokens = userConfig => {
|
29
|
-
|
30
|
-
|
31
|
-
designSystem
|
32
|
-
}
|
33
|
-
} = userConfig; // TODO: Type to be filled
|
34
|
-
|
22
|
+
var _userConfig$source;
|
23
|
+
const designSystem = (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.designSystem;
|
35
24
|
const tailwindcssConfig = {};
|
36
|
-
tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {};
|
25
|
+
tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {};
|
37
26
|
|
27
|
+
// not use default design token when designToken.defaultTheme is false or theme is false
|
38
28
|
if (!designSystem) {
|
39
29
|
tailwindcssConfig.presets = [];
|
40
|
-
}
|
41
|
-
|
30
|
+
}
|
42
31
|
|
32
|
+
// when only designSystem exist, need remove supportStyledComponents
|
43
33
|
if (designSystem) {
|
44
34
|
delete tailwindcssConfig.theme.supportStyledComponents;
|
45
35
|
}
|
46
|
-
|
47
36
|
return resolveConfig(tailwindcssConfig).theme || {};
|
48
37
|
};
|
49
|
-
|
50
38
|
return {
|
51
39
|
config() {
|
52
40
|
const appContext = api.useAppContext();
|
@@ -57,25 +45,21 @@ var _default = ({
|
|
57
45
|
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
58
46
|
}
|
59
47
|
},
|
60
|
-
tools: {
|
48
|
+
tools: {
|
49
|
+
// TODO: support less、scss、css vars
|
61
50
|
// less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
|
62
51
|
// sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
|
63
52
|
// postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
|
64
53
|
}
|
65
54
|
};
|
66
55
|
},
|
67
|
-
|
68
56
|
modifyEntryImports({
|
69
57
|
entrypoint,
|
70
58
|
imports
|
71
59
|
}) {
|
60
|
+
var _userConfig$source$de, _userConfig$source2;
|
72
61
|
const userConfig = api.useResolvedConfigContext();
|
73
|
-
const {
|
74
|
-
source: {
|
75
|
-
designSystem
|
76
|
-
}
|
77
|
-
} = userConfig;
|
78
|
-
|
62
|
+
const designSystem = (_userConfig$source$de = (_userConfig$source2 = userConfig.source) === null || _userConfig$source2 === void 0 ? void 0 : _userConfig$source2.designSystem) !== null && _userConfig$source$de !== void 0 ? _userConfig$source$de : {};
|
79
63
|
if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
|
80
64
|
const designTokens = getDesignTokens(userConfig);
|
81
65
|
imports.push({
|
@@ -88,54 +72,42 @@ var _default = ({
|
|
88
72
|
`
|
89
73
|
});
|
90
74
|
}
|
91
|
-
|
92
75
|
return {
|
93
76
|
entrypoint,
|
94
77
|
imports
|
95
78
|
};
|
96
79
|
},
|
97
|
-
|
98
80
|
modifyEntryRuntimePlugins({
|
99
81
|
entrypoint,
|
100
82
|
plugins
|
101
83
|
}) {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
}
|
106
|
-
} = api.useResolvedConfigContext();
|
84
|
+
var _userConfig$source$de2, _userConfig$source3;
|
85
|
+
const userConfig = api.useResolvedConfigContext();
|
86
|
+
const designSystem = (_userConfig$source$de2 = (_userConfig$source3 = userConfig.source) === null || _userConfig$source3 === void 0 ? void 0 : _userConfig$source3.designSystem) !== null && _userConfig$source$de2 !== void 0 ? _userConfig$source$de2 : {};
|
107
87
|
let useSCThemeProvider = true;
|
108
|
-
|
109
88
|
if (designSystem) {
|
110
89
|
// when designSystem exist, designToken.styledComponents`s default value is false.
|
111
90
|
useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
|
112
91
|
}
|
113
|
-
|
114
92
|
if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
|
115
93
|
plugins.push({
|
116
94
|
name: PLUGIN_IDENTIFIER,
|
117
95
|
options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? 'true' : 'false'}, useDesignTokenContext: false}`
|
118
96
|
});
|
119
97
|
}
|
120
|
-
|
121
98
|
return {
|
122
99
|
entrypoint,
|
123
100
|
plugins
|
124
101
|
};
|
125
102
|
},
|
126
|
-
|
127
103
|
validateSchema() {
|
128
104
|
// add source.designSystem.supportStyledComponents config
|
129
105
|
return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
|
130
106
|
},
|
131
|
-
|
132
107
|
addRuntimeExports() {
|
133
108
|
pluginsExportsUtils.addExport(`export { default as designToken } from '${pluginName}/runtime-design-token'`);
|
134
109
|
}
|
135
|
-
|
136
110
|
};
|
137
111
|
}
|
138
|
-
|
139
112
|
});
|
140
|
-
|
141
113
|
exports.default = _default;
|
@@ -10,9 +10,7 @@ Object.defineProperty(exports, "default", {
|
|
10
10
|
return _runtime.default;
|
11
11
|
}
|
12
12
|
});
|
13
|
-
|
14
13
|
var _runtime = _interopRequireWildcard(require("./runtime"));
|
15
|
-
|
16
14
|
Object.keys(_runtime).forEach(function (key) {
|
17
15
|
if (key === "default" || key === "__esModule") return;
|
18
16
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
@@ -24,7 +22,5 @@ Object.keys(_runtime).forEach(function (key) {
|
|
24
22
|
}
|
25
23
|
});
|
26
24
|
});
|
27
|
-
|
28
25
|
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
26
|
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; }
|
@@ -4,24 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
|
8
7
|
var _default = ({
|
9
8
|
cssVarsHash: _cssVarsHash = {}
|
10
9
|
} = {}) => ({
|
11
10
|
postcssPlugin: 'postcss-replace-css-vars',
|
12
|
-
|
13
11
|
Declaration(decl) {
|
14
12
|
if (decl.value && typeof decl.value === 'string') {
|
15
13
|
decl.value = decl.value.replace(/--\S*/g, match => {
|
16
14
|
if (_cssVarsHash[match]) {
|
17
15
|
return _cssVarsHash[match];
|
18
16
|
}
|
19
|
-
|
20
17
|
return match;
|
21
18
|
});
|
22
19
|
}
|
23
20
|
}
|
24
|
-
|
25
21
|
});
|
26
|
-
|
27
22
|
exports.default = _default;
|
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
var _exportNames = {};
|
7
7
|
exports.default = void 0;
|
8
|
-
|
9
8
|
var _plugin = _interopRequireWildcard(require("./plugin"));
|
10
|
-
|
11
9
|
Object.keys(_plugin).forEach(function (key) {
|
12
10
|
if (key === "default" || key === "__esModule") return;
|
13
11
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
@@ -19,10 +17,7 @@ Object.keys(_plugin).forEach(function (key) {
|
|
19
17
|
}
|
20
18
|
});
|
21
19
|
});
|
22
|
-
|
23
20
|
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); }
|
24
|
-
|
25
21
|
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; }
|
26
|
-
|
27
22
|
var _default = _plugin.default;
|
28
23
|
exports.default = _default;
|
@@ -4,33 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.useDesignTokens = exports.default = exports.DesignTokenContext = void 0;
|
7
|
-
|
8
7
|
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
9
|
-
|
10
8
|
var _react = _interopRequireWildcard(require("react"));
|
11
|
-
|
12
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
13
|
-
|
14
10
|
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); }
|
15
|
-
|
16
11
|
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; }
|
17
|
-
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
-
|
20
13
|
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; }
|
21
|
-
|
22
14
|
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; }
|
23
|
-
|
24
15
|
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; }
|
25
|
-
|
26
16
|
const DesignTokenContext = /*#__PURE__*/_react.default.createContext({});
|
27
|
-
|
28
17
|
exports.DesignTokenContext = DesignTokenContext;
|
29
|
-
|
30
18
|
const useDesignTokens = () => (0, _react.useContext)(DesignTokenContext);
|
31
|
-
|
32
19
|
exports.useDesignTokens = useDesignTokens;
|
33
|
-
|
34
20
|
var _default = (options = {}) => ({
|
35
21
|
name: '@modern-js/plugin-design-token',
|
36
22
|
setup: () => ({
|
@@ -43,12 +29,10 @@ var _default = (options = {}) => ({
|
|
43
29
|
useStyledComponentsThemeProvider = false,
|
44
30
|
useDesignTokenContext = false
|
45
31
|
} = options;
|
46
|
-
|
47
32
|
if (useStyledComponentsThemeProvider && useDesignTokenContext) {
|
48
33
|
const {
|
49
34
|
ThemeProvider
|
50
35
|
} = require('@modern-js/runtime/styled');
|
51
|
-
|
52
36
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeProvider, {
|
53
37
|
theme: token,
|
54
38
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DesignTokenContext.Provider, {
|
@@ -60,7 +44,6 @@ var _default = (options = {}) => ({
|
|
60
44
|
const {
|
61
45
|
ThemeProvider
|
62
46
|
} = require('@modern-js/runtime/styled');
|
63
|
-
|
64
47
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeProvider, {
|
65
48
|
theme: token,
|
66
49
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
|
@@ -74,13 +57,10 @@ var _default = (options = {}) => ({
|
|
74
57
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props));
|
75
58
|
}
|
76
59
|
};
|
77
|
-
|
78
60
|
return next({
|
79
61
|
App: (0, _hoistNonReactStatics.default)(DesignTokenAppWrapper, App)
|
80
62
|
});
|
81
63
|
}
|
82
|
-
|
83
64
|
})
|
84
65
|
});
|
85
|
-
|
86
66
|
exports.default = _default;
|
package/dist/js/node/index.js
CHANGED
package/dist/js/node/tailwind.js
CHANGED
@@ -4,25 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.getTailwindConfig = void 0;
|
7
|
-
|
8
7
|
var _utils = require("@modern-js/utils");
|
9
|
-
|
10
8
|
var _lodash = require("@modern-js/utils/lodash");
|
11
|
-
|
12
9
|
const checkIfExistNotAllowKeys = tailwindConfig => {
|
13
10
|
const notAllowExistKeys = ['theme'];
|
14
11
|
let notAllowKey = '';
|
15
12
|
const ret = Object.keys(tailwindConfig).some(key => notAllowExistKeys.includes(key) && (notAllowKey = key));
|
16
13
|
return [ret, notAllowKey];
|
17
14
|
};
|
18
|
-
|
19
15
|
const getPureDesignSystemConfig = designSystemConfig => {
|
20
16
|
const pureDesignSystemConfig = (0, _lodash.cloneDeep)(designSystemConfig);
|
21
17
|
delete pureDesignSystemConfig.supportStyledComponents;
|
22
18
|
return pureDesignSystemConfig;
|
23
19
|
};
|
24
|
-
|
25
20
|
const getTailwindConfig = (config, option = {}) => {
|
21
|
+
var _ref, _designSystem;
|
26
22
|
const purgeConfig = (0, _lodash.merge)({
|
27
23
|
// TODO: how the operating environment is determined
|
28
24
|
enabled: process.env.NODE_ENV === 'production',
|
@@ -34,19 +30,16 @@ const getTailwindConfig = (config, option = {}) => {
|
|
34
30
|
purge: purgeConfig
|
35
31
|
};
|
36
32
|
const tailwindConfig = (0, _utils.applyOptionsChain)(defaultTailwindConfig, config.tools.tailwindcss || {});
|
37
|
-
const designSystem = getPureDesignSystemConfig(config.source.designSystem
|
33
|
+
const designSystem = getPureDesignSystemConfig((_ref = (_designSystem = config.designSystem) !== null && _designSystem !== void 0 ? _designSystem : config.source.designSystem) !== null && _ref !== void 0 ? _ref : {});
|
38
34
|
const [exist, key] = checkIfExistNotAllowKeys(tailwindConfig);
|
39
|
-
|
40
35
|
if (exist) {
|
41
|
-
_utils.logger.error(`should not exist '${key}' on tools.tailwindcss, please remove it`);
|
42
|
-
|
43
|
-
|
36
|
+
_utils.logger.error(`should not exist '${key}' on tools.tailwindcss, please remove it`);
|
37
|
+
// eslint-disable-next-line no-process-exit
|
44
38
|
process.exit(0);
|
45
|
-
}
|
46
|
-
|
39
|
+
}
|
47
40
|
|
41
|
+
// Because there is no default theme configuration
|
48
42
|
tailwindConfig.theme = designSystem || {};
|
49
43
|
return tailwindConfig;
|
50
44
|
};
|
51
|
-
|
52
45
|
exports.getTailwindConfig = getTailwindConfig;
|
File without changes
|
package/dist/js/node/utils.js
CHANGED
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.template = exports.checkTwinMacroNotExist = void 0;
|
7
|
-
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
9
|
-
|
10
8
|
var _utils = require("@modern-js/utils");
|
11
|
-
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
-
|
14
10
|
const template = configPath => `
|
15
11
|
function _interopRequireDefault(obj) {
|
16
12
|
return obj && obj.__esModule ? obj : { default: obj };
|
@@ -31,20 +27,15 @@ module.exports = {
|
|
31
27
|
...tailwindcss,
|
32
28
|
};
|
33
29
|
`;
|
34
|
-
|
35
30
|
exports.template = template;
|
36
|
-
|
37
31
|
const checkTwinMacroNotExist = async appDirectory => {
|
38
32
|
const depName = 'twin.macro';
|
39
33
|
const packageJson = (await _utils.fs.readJSON(_path.default.join(appDirectory, 'package.json'), {
|
40
34
|
throws: false
|
41
35
|
})) || {};
|
42
|
-
|
43
36
|
if (typeof packageJson.dependencies === 'object' && packageJson.dependencies[depName] || typeof packageJson.devDependencies === 'object' && packageJson.devDependencies[depName]) {
|
44
37
|
return false;
|
45
38
|
}
|
46
|
-
|
47
39
|
return true;
|
48
40
|
};
|
49
|
-
|
50
41
|
exports.checkTwinMacroNotExist = checkTwinMacroNotExist;
|
@@ -12,10 +12,9 @@ export var getRandomTwConfigFileName = function getRandomTwConfigFileName(intern
|
|
12
12
|
};
|
13
13
|
export default (function () {
|
14
14
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
pluginName: '@modern-js/plugin-tailwindcss'
|
16
|
+
},
|
17
|
+
pluginName = _ref.pluginName;
|
19
18
|
return {
|
20
19
|
name: '@modern-js/plugin-tailwindcss',
|
21
20
|
// support designSystem.supportStyledComponents
|
@@ -25,17 +24,14 @@ export default (function () {
|
|
25
24
|
setup: function () {
|
26
25
|
var _setup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
|
27
26
|
var _api$useAppContext, appDirectory, internalDirectory, internalTwConfigPath, notHaveTwinMacro;
|
28
|
-
|
29
27
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
30
28
|
while (1) {
|
31
29
|
switch (_context.prev = _context.next) {
|
32
30
|
case 0:
|
33
31
|
_api$useAppContext = api.useAppContext(), appDirectory = _api$useAppContext.appDirectory, internalDirectory = _api$useAppContext.internalDirectory;
|
34
32
|
internalTwConfigPath = ''; // When reinstalling dependencies, most of the time the project will be restarted
|
35
|
-
|
36
33
|
_context.next = 4;
|
37
34
|
return checkTwinMacroNotExist(appDirectory);
|
38
|
-
|
39
35
|
case 4:
|
40
36
|
notHaveTwinMacro = _context.sent;
|
41
37
|
return _context.abrupt("return", {
|
@@ -43,13 +39,11 @@ export default (function () {
|
|
43
39
|
if (notHaveTwinMacro) {
|
44
40
|
return;
|
45
41
|
}
|
46
|
-
|
47
42
|
internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
|
48
43
|
var globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, '*.cjs'));
|
49
44
|
var files = globby.sync(globPattern, {
|
50
45
|
absolute: true
|
51
46
|
});
|
52
|
-
|
53
47
|
if (files.length > 0) {
|
54
48
|
fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), 'utf-8');
|
55
49
|
}
|
@@ -64,26 +58,44 @@ export default (function () {
|
|
64
58
|
// TODO: In module project, also is called, but should not be called.
|
65
59
|
postcss: function postcss(config) {
|
66
60
|
var modernConfig = api.useResolvedConfigContext();
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
61
|
+
if (!config.postcssOptions
|
62
|
+
// config.$$tools === 'module-tools'
|
63
|
+
) {
|
64
|
+
if (Array.isArray(config.plugins)) {
|
65
|
+
var tailwindConfig = getTailwindConfig(modernConfig, {
|
66
|
+
pureConfig: {
|
67
|
+
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']
|
68
|
+
}
|
69
|
+
});
|
70
|
+
config.plugins.push(require('tailwindcss')(tailwindConfig));
|
71
|
+
} else {
|
72
|
+
var _tailwindConfig = getTailwindConfig(modernConfig, {
|
73
|
+
pureConfig: {
|
74
|
+
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']
|
75
|
+
}
|
76
|
+
});
|
77
|
+
config.plugins = [require('tailwindcss')(_tailwindConfig)];
|
71
78
|
}
|
72
|
-
});
|
73
|
-
|
74
|
-
if (Array.isArray(config.postcssOptions.plugins)) {
|
75
|
-
config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
|
76
79
|
} else {
|
77
|
-
|
80
|
+
var _tailwindConfig2 = getTailwindConfig(modernConfig, {
|
81
|
+
pureConfig: {
|
82
|
+
content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx',
|
83
|
+
// about storybook
|
84
|
+
'./storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
|
85
|
+
}
|
86
|
+
});
|
87
|
+
if (Array.isArray(config.postcssOptions.plugins)) {
|
88
|
+
config.postcssOptions.plugins.push(require('tailwindcss')(_tailwindConfig2));
|
89
|
+
} else {
|
90
|
+
config.postcssOptions.plugins = [require('tailwindcss')(_tailwindConfig2)];
|
91
|
+
}
|
78
92
|
}
|
79
93
|
},
|
80
94
|
babel: function babel(config) {
|
81
95
|
var _config$plugins;
|
82
|
-
|
83
96
|
if (notHaveTwinMacro) {
|
84
97
|
return;
|
85
98
|
}
|
86
|
-
|
87
99
|
var twinConfig = {
|
88
100
|
twin: {
|
89
101
|
preset: supportCssInJsLibrary,
|
@@ -94,36 +106,24 @@ export default (function () {
|
|
94
106
|
if (Array.isArray(plugin) && plugin[0]) {
|
95
107
|
var pluginTarget = plugin[0];
|
96
108
|
var pluginOptions = plugin[1];
|
97
|
-
|
98
|
-
|
109
|
+
if (typeof pluginTarget === 'string' &&
|
110
|
+
// TODO: use babel chain
|
99
111
|
slash(pluginTarget).includes('compiled/babel-plugin-macros')) {
|
100
112
|
if (pluginOptions) {
|
101
113
|
pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
|
102
114
|
} else {
|
103
115
|
plugin.push(twinConfig);
|
104
116
|
}
|
105
|
-
|
106
117
|
return true;
|
107
118
|
}
|
108
119
|
}
|
109
|
-
|
110
120
|
return false;
|
111
121
|
});
|
112
122
|
}
|
113
123
|
}
|
114
124
|
};
|
115
|
-
},
|
116
|
-
moduleTailwindConfig: function moduleTailwindConfig() {
|
117
|
-
var modernConfig = api.useResolvedConfigContext();
|
118
|
-
var tailwindConfig = getTailwindConfig(modernConfig, {
|
119
|
-
pureConfig: {
|
120
|
-
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']
|
121
|
-
}
|
122
|
-
});
|
123
|
-
return require('tailwindcss')(tailwindConfig);
|
124
125
|
}
|
125
126
|
});
|
126
|
-
|
127
127
|
case 6:
|
128
128
|
case "end":
|
129
129
|
return _context.stop();
|
@@ -131,11 +131,9 @@ export default (function () {
|
|
131
131
|
}
|
132
132
|
}, _callee);
|
133
133
|
}));
|
134
|
-
|
135
134
|
function setup(_x) {
|
136
135
|
return _setup.apply(this, arguments);
|
137
136
|
}
|
138
|
-
|
139
137
|
return setup;
|
140
138
|
}()
|
141
139
|
};
|
@@ -3,36 +3,32 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
3
|
import { lazyImport, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from '@modern-js/utils';
|
4
4
|
export default (function () {
|
5
5
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
pluginName: '@modern-js/plugin-tailwindcss'
|
7
|
+
},
|
8
|
+
pluginName = _ref.pluginName;
|
10
9
|
return {
|
11
10
|
name: '@modern-js/plugin-design-token',
|
12
11
|
setup: function setup(api) {
|
13
12
|
var pluginsExportsUtils;
|
14
13
|
var resolveConfig = lazyImport('tailwindcss/resolveConfig', require);
|
15
14
|
var PLUGIN_IDENTIFIER = 'designToken';
|
16
|
-
|
17
15
|
var getDesignTokens = function getDesignTokens(userConfig) {
|
18
|
-
var
|
19
|
-
|
20
|
-
|
16
|
+
var _userConfig$source;
|
17
|
+
var designSystem = (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.designSystem;
|
21
18
|
var tailwindcssConfig = {};
|
22
|
-
tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {};
|
19
|
+
tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {};
|
23
20
|
|
21
|
+
// not use default design token when designToken.defaultTheme is false or theme is false
|
24
22
|
if (!designSystem) {
|
25
23
|
tailwindcssConfig.presets = [];
|
26
|
-
}
|
27
|
-
|
24
|
+
}
|
28
25
|
|
26
|
+
// when only designSystem exist, need remove supportStyledComponents
|
29
27
|
if (designSystem) {
|
30
28
|
delete tailwindcssConfig.theme.supportStyledComponents;
|
31
29
|
}
|
32
|
-
|
33
30
|
return resolveConfig(tailwindcssConfig).theme || {};
|
34
31
|
};
|
35
|
-
|
36
32
|
return {
|
37
33
|
config: function config() {
|
38
34
|
var appContext = api.useAppContext();
|
@@ -43,19 +39,20 @@ export default (function () {
|
|
43
39
|
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
44
40
|
}
|
45
41
|
},
|
46
|
-
tools: {
|
42
|
+
tools: {
|
43
|
+
// TODO: support less、scss、css vars
|
47
44
|
// less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
|
48
45
|
// sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
|
49
46
|
// postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
|
50
47
|
}
|
51
48
|
};
|
52
49
|
},
|
53
|
-
modifyEntryImports: function modifyEntryImports(
|
54
|
-
var
|
55
|
-
|
50
|
+
modifyEntryImports: function modifyEntryImports(_ref2) {
|
51
|
+
var _userConfig$source$de, _userConfig$source2;
|
52
|
+
var entrypoint = _ref2.entrypoint,
|
53
|
+
imports = _ref2.imports;
|
56
54
|
var userConfig = api.useResolvedConfigContext();
|
57
|
-
var designSystem = userConfig.source.designSystem;
|
58
|
-
|
55
|
+
var designSystem = (_userConfig$source$de = (_userConfig$source2 = userConfig.source) === null || _userConfig$source2 === void 0 ? void 0 : _userConfig$source2.designSystem) !== null && _userConfig$source$de !== void 0 ? _userConfig$source$de : {};
|
59
56
|
if (_typeof(designSystem) === 'object' && designSystem.supportStyledComponents) {
|
60
57
|
var designTokens = getDesignTokens(userConfig);
|
61
58
|
imports.push({
|
@@ -66,33 +63,28 @@ export default (function () {
|
|
66
63
|
initialize: "\n const designTokens = ".concat(JSON.stringify(designTokens), ";\n ")
|
67
64
|
});
|
68
65
|
}
|
69
|
-
|
70
66
|
return {
|
71
67
|
entrypoint: entrypoint,
|
72
68
|
imports: imports
|
73
69
|
};
|
74
70
|
},
|
75
|
-
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(
|
76
|
-
var
|
77
|
-
|
78
|
-
|
79
|
-
var
|
80
|
-
|
81
|
-
|
71
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref3) {
|
72
|
+
var _userConfig$source$de2, _userConfig$source3;
|
73
|
+
var entrypoint = _ref3.entrypoint,
|
74
|
+
plugins = _ref3.plugins;
|
75
|
+
var userConfig = api.useResolvedConfigContext();
|
76
|
+
var designSystem = (_userConfig$source$de2 = (_userConfig$source3 = userConfig.source) === null || _userConfig$source3 === void 0 ? void 0 : _userConfig$source3.designSystem) !== null && _userConfig$source$de2 !== void 0 ? _userConfig$source$de2 : {};
|
82
77
|
var useSCThemeProvider = true;
|
83
|
-
|
84
78
|
if (designSystem) {
|
85
79
|
// when designSystem exist, designToken.styledComponents`s default value is false.
|
86
80
|
useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
|
87
81
|
}
|
88
|
-
|
89
82
|
if (_typeof(designSystem) === 'object' && designSystem.supportStyledComponents) {
|
90
83
|
plugins.push({
|
91
84
|
name: PLUGIN_IDENTIFIER,
|
92
85
|
options: "{token: designTokens, useStyledComponentsThemeProvider: ".concat(useSCThemeProvider ? 'true' : 'false', ", useDesignTokenContext: false}")
|
93
86
|
});
|
94
87
|
}
|
95
|
-
|
96
88
|
return {
|
97
89
|
entrypoint: entrypoint,
|
98
90
|
plugins: plugins
|