@modern-js/plugin-tailwindcss 1.4.2 → 1.15.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/js/modern/cli.js +126 -0
  3. package/dist/js/modern/design-token/cli/index.js +131 -0
  4. package/dist/js/modern/design-token/index.js +2 -0
  5. package/dist/js/modern/design-token/postcss-plugin/index.js +18 -0
  6. package/dist/js/modern/design-token/runtime/index.js +3 -0
  7. package/dist/js/modern/design-token/runtime/plugin.js +62 -0
  8. package/dist/js/modern/index.js +1 -0
  9. package/dist/js/modern/tailwind.js +43 -0
  10. package/dist/js/modern/utils.js +34 -0
  11. package/dist/js/node/cli.js +9 -3
  12. package/dist/js/node/design-token/cli/index.js +141 -0
  13. package/dist/js/node/design-token/index.js +30 -0
  14. package/dist/js/node/design-token/postcss-plugin/index.js +27 -0
  15. package/dist/js/node/design-token/runtime/index.js +28 -0
  16. package/dist/js/node/design-token/runtime/plugin.js +86 -0
  17. package/dist/js/treeshaking/cli.js +142 -0
  18. package/dist/js/treeshaking/design-token/cli/index.js +111 -0
  19. package/dist/js/treeshaking/design-token/index.js +2 -0
  20. package/dist/js/treeshaking/design-token/postcss-plugin/index.js +30 -0
  21. package/dist/js/treeshaking/design-token/runtime/index.js +3 -0
  22. package/dist/js/treeshaking/design-token/runtime/plugin.js +62 -0
  23. package/dist/js/treeshaking/index.js +1 -0
  24. package/dist/js/treeshaking/tailwind.js +51 -0
  25. package/dist/js/treeshaking/utils.js +56 -0
  26. package/dist/types/cli.d.ts +5 -1
  27. package/dist/types/design-token/cli/index.d.ts +9 -0
  28. package/dist/types/design-token/index.d.ts +2 -0
  29. package/dist/types/design-token/postcss-plugin/index.d.ts +12 -0
  30. package/dist/types/design-token/runtime/index.d.ts +3 -0
  31. package/dist/types/design-token/runtime/plugin.d.ts +12 -0
  32. package/package.json +29 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # @modern-js/plugin-tailwindcss
2
2
 
3
+ ## 1.15.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8658a78]
8
+ - Updated dependencies [335c97c]
9
+ - Updated dependencies [05d4a4f]
10
+ - Updated dependencies [ad05af9]
11
+ - Updated dependencies [5d53d1c]
12
+ - Updated dependencies [37cd159]
13
+ - Updated dependencies [a04a11b]
14
+ - @modern-js/utils@1.15.0
15
+ - @modern-js/runtime@1.15.0
16
+
17
+ ## 1.5.1
18
+
19
+ ### Patch Changes
20
+
21
+ - 3c874ca16: fix: `@modern-js/plugin-tailwindcss` support `pluginName` params
22
+
23
+ fix: `@modern-js/plugin-tailwindcss` 支持 `pluginName` 参数
24
+
25
+ ## 1.5.0
26
+
27
+ ### Minor Changes
28
+
29
+ - 79e83ef: chore: merge `@modern-js/plugin-design-token` to `@modern-js/plugin-tailwindcss`
30
+
31
+ chore: 合并 `@modern-js/plugin-design-token` 到 `@modern-js/plugin-tailwindcss`
32
+
33
+ - 59c941a: chore(runtime): merge `@modern-js/runtime-core` to `@modern-js/runtime`
34
+
35
+ chore(runtime): 合并 `@modern-js/runtime-core` 到 `@modern-js/runtime`
36
+
37
+ ### Patch Changes
38
+
39
+ - Updated dependencies [79e83ef]
40
+ - Updated dependencies [e0cd14a]
41
+ - Updated dependencies [287ac8b]
42
+ - Updated dependencies [22f4dca]
43
+ - Updated dependencies [59c941a]
44
+ - Updated dependencies [7b9067f]
45
+ - @modern-js/utils@1.9.0
46
+ - @modern-js/runtime@1.5.0
47
+
3
48
  ## 1.4.2
4
49
 
5
50
  ### Patch Changes
@@ -0,0 +1,126 @@
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
+ pluginName
18
+ } = {
19
+ pluginName: '@modern-js/plugin-tailwindcss'
20
+ }) => ({
21
+ name: '@modern-js/plugin-tailwindcss',
22
+ // support designSystem.supportStyledComponents
23
+ usePlugins: [DesignTokenPlugin({
24
+ pluginName
25
+ })],
26
+ setup: async api => {
27
+ const {
28
+ appDirectory,
29
+ internalDirectory
30
+ } = api.useAppContext();
31
+ let internalTwConfigPath = ''; // When reinstalling dependencies, most of the time the project will be restarted
32
+
33
+ const notHaveTwinMacro = await checkTwinMacroNotExist(appDirectory);
34
+ return {
35
+ prepare() {
36
+ if (notHaveTwinMacro) {
37
+ return;
38
+ }
39
+
40
+ internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
41
+ const globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, '*.cjs'));
42
+ const files = globby.sync(globPattern, {
43
+ absolute: true
44
+ });
45
+
46
+ if (files.length > 0) {
47
+ fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), 'utf-8');
48
+ }
49
+ },
50
+
51
+ validateSchema() {
52
+ return PLUGIN_SCHEMAS['@modern-js/plugin-tailwindcss'];
53
+ },
54
+
55
+ config() {
56
+ return {
57
+ tools: {
58
+ // TODO: Add interface about postcss config
59
+ // TODO: In module project, also is called, but should not be called.
60
+ postcss: config => {
61
+ const modernConfig = api.useResolvedConfigContext();
62
+ const tailwindConfig = getTailwindConfig(modernConfig, {
63
+ pureConfig: {
64
+ content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', // about storybook
65
+ './storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
66
+ }
67
+ });
68
+
69
+ if (Array.isArray(config.postcssOptions.plugins)) {
70
+ config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
71
+ } else {
72
+ config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
73
+ }
74
+ },
75
+
76
+ babel(config) {
77
+ var _config$plugins;
78
+
79
+ if (notHaveTwinMacro) {
80
+ return;
81
+ }
82
+
83
+ const twinConfig = {
84
+ twin: {
85
+ preset: supportCssInJsLibrary,
86
+ config: internalTwConfigPath
87
+ }
88
+ };
89
+ (_config$plugins = config.plugins) === null || _config$plugins === void 0 ? void 0 : _config$plugins.some(plugin => {
90
+ if (Array.isArray(plugin) && plugin[0]) {
91
+ const pluginTarget = plugin[0];
92
+ let pluginOptions = plugin[1];
93
+
94
+ if (typeof pluginTarget === 'string' && // TODO: use babel chain
95
+ slash(pluginTarget).includes('compiled/babel-plugin-macros')) {
96
+ if (pluginOptions) {
97
+ pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
98
+ } else {
99
+ plugin.push(twinConfig);
100
+ }
101
+
102
+ return true;
103
+ }
104
+ }
105
+
106
+ return false;
107
+ });
108
+ }
109
+
110
+ }
111
+ };
112
+ },
113
+
114
+ moduleTailwindConfig() {
115
+ const modernConfig = api.useResolvedConfigContext();
116
+ const tailwindConfig = getTailwindConfig(modernConfig, {
117
+ pureConfig: {
118
+ 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']
119
+ }
120
+ });
121
+ return require('tailwindcss')(tailwindConfig);
122
+ }
123
+
124
+ };
125
+ }
126
+ }));
@@ -0,0 +1,131 @@
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
+ pluginName
10
+ } = {
11
+ pluginName: '@modern-js/plugin-tailwindcss'
12
+ }) => ({
13
+ name: '@modern-js/plugin-design-token',
14
+
15
+ setup(api) {
16
+ let pluginsExportsUtils;
17
+ const resolveConfig = lazyImport('tailwindcss/resolveConfig', require);
18
+ const PLUGIN_IDENTIFIER = 'designToken';
19
+
20
+ const getDesignTokens = userConfig => {
21
+ const {
22
+ source: {
23
+ designSystem
24
+ }
25
+ } = userConfig; // TODO: Type to be filled
26
+
27
+ const tailwindcssConfig = {};
28
+ tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {}; // not use default design token when designToken.defaultTheme is false or theme is false
29
+
30
+ if (!designSystem) {
31
+ tailwindcssConfig.presets = [];
32
+ } // when only designSystem exist, need remove supportStyledComponents
33
+
34
+
35
+ if (designSystem) {
36
+ delete tailwindcssConfig.theme.supportStyledComponents;
37
+ }
38
+
39
+ return resolveConfig(tailwindcssConfig).theme || {};
40
+ };
41
+
42
+ return {
43
+ config() {
44
+ const appContext = api.useAppContext();
45
+ pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'plugins');
46
+ return {
47
+ source: {
48
+ alias: {
49
+ '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
50
+ }
51
+ },
52
+ tools: {// TODO: support less、scss、css vars
53
+ // less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
54
+ // sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
55
+ // postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
56
+ }
57
+ };
58
+ },
59
+
60
+ modifyEntryImports({
61
+ entrypoint,
62
+ imports
63
+ }) {
64
+ const userConfig = api.useResolvedConfigContext();
65
+ const {
66
+ source: {
67
+ designSystem
68
+ }
69
+ } = userConfig;
70
+
71
+ if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
72
+ const designTokens = getDesignTokens(userConfig);
73
+ imports.push({
74
+ value: '@modern-js/runtime/plugins',
75
+ specifiers: [{
76
+ imported: PLUGIN_IDENTIFIER
77
+ }],
78
+ initialize: `
79
+ const designTokens = ${JSON.stringify(designTokens)};
80
+ `
81
+ });
82
+ }
83
+
84
+ return {
85
+ entrypoint,
86
+ imports
87
+ };
88
+ },
89
+
90
+ modifyEntryRuntimePlugins({
91
+ entrypoint,
92
+ plugins
93
+ }) {
94
+ const {
95
+ source: {
96
+ designSystem
97
+ }
98
+ } = api.useResolvedConfigContext();
99
+ let useSCThemeProvider = true;
100
+
101
+ if (designSystem) {
102
+ // when designSystem exist, designToken.styledComponents`s default value is false.
103
+ useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
104
+ }
105
+
106
+ if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
107
+ plugins.push({
108
+ name: PLUGIN_IDENTIFIER,
109
+ options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? 'true' : 'false'}, useDesignTokenContext: false}`
110
+ });
111
+ }
112
+
113
+ return {
114
+ entrypoint,
115
+ plugins
116
+ };
117
+ },
118
+
119
+ validateSchema() {
120
+ // add source.designSystem.supportStyledComponents config
121
+ return PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
122
+ },
123
+
124
+ addRuntimeExports() {
125
+ pluginsExportsUtils.addExport(`export { default as designToken } from '${pluginName}/runtime-design-token'`);
126
+ }
127
+
128
+ };
129
+ }
130
+
131
+ }));
@@ -0,0 +1,2 @@
1
+ export { default } from "./runtime";
2
+ export * from "./runtime";
@@ -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,3 @@
1
+ import designTokenPlugin from "./plugin";
2
+ export * from "./plugin";
3
+ export default designTokenPlugin;
@@ -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
+ };
@@ -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("@modern-js/plugin-design-token/cli"));
12
+ var _cli = _interopRequireDefault(require("./design-token/cli"));
13
13
 
14
14
  var _tailwind = require("./tailwind");
15
15
 
@@ -31,10 +31,16 @@ const getRandomTwConfigFileName = internalDirectory => {
31
31
 
32
32
  exports.getRandomTwConfigFileName = getRandomTwConfigFileName;
33
33
 
34
- var _default = () => ({
34
+ var _default = ({
35
+ pluginName
36
+ } = {
37
+ pluginName: '@modern-js/plugin-tailwindcss'
38
+ }) => ({
35
39
  name: '@modern-js/plugin-tailwindcss',
36
40
  // support designSystem.supportStyledComponents
37
- usePlugins: [(0, _cli.default)()],
41
+ usePlugins: [(0, _cli.default)({
42
+ pluginName
43
+ })],
38
44
  setup: async api => {
39
45
  const {
40
46
  appDirectory,
@@ -0,0 +1,141 @@
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
+ pluginName
18
+ } = {
19
+ pluginName: '@modern-js/plugin-tailwindcss'
20
+ }) => ({
21
+ name: '@modern-js/plugin-design-token',
22
+
23
+ setup(api) {
24
+ let pluginsExportsUtils;
25
+ const resolveConfig = (0, _utils.lazyImport)('tailwindcss/resolveConfig', require);
26
+ const PLUGIN_IDENTIFIER = 'designToken';
27
+
28
+ const getDesignTokens = userConfig => {
29
+ const {
30
+ source: {
31
+ designSystem
32
+ }
33
+ } = userConfig; // TODO: Type to be filled
34
+
35
+ const tailwindcssConfig = {};
36
+ tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {}; // not use default design token when designToken.defaultTheme is false or theme is false
37
+
38
+ if (!designSystem) {
39
+ tailwindcssConfig.presets = [];
40
+ } // when only designSystem exist, need remove supportStyledComponents
41
+
42
+
43
+ if (designSystem) {
44
+ delete tailwindcssConfig.theme.supportStyledComponents;
45
+ }
46
+
47
+ return resolveConfig(tailwindcssConfig).theme || {};
48
+ };
49
+
50
+ return {
51
+ config() {
52
+ const appContext = api.useAppContext();
53
+ pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'plugins');
54
+ return {
55
+ source: {
56
+ alias: {
57
+ '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
58
+ }
59
+ },
60
+ tools: {// TODO: support less、scss、css vars
61
+ // less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
62
+ // sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
63
+ // postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
64
+ }
65
+ };
66
+ },
67
+
68
+ modifyEntryImports({
69
+ entrypoint,
70
+ imports
71
+ }) {
72
+ const userConfig = api.useResolvedConfigContext();
73
+ const {
74
+ source: {
75
+ designSystem
76
+ }
77
+ } = userConfig;
78
+
79
+ if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
80
+ const designTokens = getDesignTokens(userConfig);
81
+ imports.push({
82
+ value: '@modern-js/runtime/plugins',
83
+ specifiers: [{
84
+ imported: PLUGIN_IDENTIFIER
85
+ }],
86
+ initialize: `
87
+ const designTokens = ${JSON.stringify(designTokens)};
88
+ `
89
+ });
90
+ }
91
+
92
+ return {
93
+ entrypoint,
94
+ imports
95
+ };
96
+ },
97
+
98
+ modifyEntryRuntimePlugins({
99
+ entrypoint,
100
+ plugins
101
+ }) {
102
+ const {
103
+ source: {
104
+ designSystem
105
+ }
106
+ } = api.useResolvedConfigContext();
107
+ let useSCThemeProvider = true;
108
+
109
+ if (designSystem) {
110
+ // when designSystem exist, designToken.styledComponents`s default value is false.
111
+ useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
112
+ }
113
+
114
+ if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
115
+ plugins.push({
116
+ name: PLUGIN_IDENTIFIER,
117
+ options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? 'true' : 'false'}, useDesignTokenContext: false}`
118
+ });
119
+ }
120
+
121
+ return {
122
+ entrypoint,
123
+ plugins
124
+ };
125
+ },
126
+
127
+ validateSchema() {
128
+ // add source.designSystem.supportStyledComponents config
129
+ return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
130
+ },
131
+
132
+ addRuntimeExports() {
133
+ pluginsExportsUtils.addExport(`export { default as designToken } from '${pluginName}/runtime-design-token'`);
134
+ }
135
+
136
+ };
137
+ }
138
+
139
+ });
140
+
141
+ 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; }