diff --git a/packages/themes/src/click.ts b/packages/themes/src/click.ts index eb8188f51e..e69de29bb2 100644 --- a/packages/themes/src/click.ts +++ b/packages/themes/src/click.ts @@ -1,4 +0,0 @@ -// eslint-disable-next-line import/no-webpack-loader-syntax -import styles from '!!css-loader!@alfalab/core-components/themes/click.css'; - -export default styles.toString(); diff --git a/packages/themes/src/corp.ts b/packages/themes/src/corp.ts index e3ae6ef286..e69de29bb2 100644 --- a/packages/themes/src/corp.ts +++ b/packages/themes/src/corp.ts @@ -1,4 +0,0 @@ -// eslint-disable-next-line import/no-webpack-loader-syntax -import styles from '!!css-loader!@alfalab/core-components/themes/corp.css'; - -export default styles.toString(); diff --git a/packages/themes/src/dark.ts b/packages/themes/src/dark.ts index b419f190ab..e69de29bb2 100644 --- a/packages/themes/src/dark.ts +++ b/packages/themes/src/dark.ts @@ -1,4 +0,0 @@ -// eslint-disable-next-line import/no-webpack-loader-syntax -import styles from '!!css-loader!@alfalab/core-components/themes/dark.css'; - -export default styles.toString(); diff --git a/packages/themes/src/intranet.ts b/packages/themes/src/intranet.ts index 796b73a5f7..e69de29bb2 100644 --- a/packages/themes/src/intranet.ts +++ b/packages/themes/src/intranet.ts @@ -1,4 +0,0 @@ -// eslint-disable-next-line import/no-webpack-loader-syntax -import styles from '!!css-loader!@alfalab/core-components/themes/intranet.css'; - -export default styles.toString(); diff --git a/packages/themes/src/mobile.ts b/packages/themes/src/mobile.ts index 4337c70d8c..e69de29bb2 100644 --- a/packages/themes/src/mobile.ts +++ b/packages/themes/src/mobile.ts @@ -1,4 +0,0 @@ -// eslint-disable-next-line import/no-webpack-loader-syntax -import styles from '!!css-loader!@alfalab/core-components/themes/mobile.css'; - -export default styles.toString(); diff --git a/packages/themes/src/site.ts b/packages/themes/src/site.ts index 7bfefa78eb..e69de29bb2 100644 --- a/packages/themes/src/site.ts +++ b/packages/themes/src/site.ts @@ -1,4 +0,0 @@ -// eslint-disable-next-line import/no-webpack-loader-syntax -import styles from '!!css-loader!@alfalab/core-components/themes/site.css'; - -export default styles.toString(); diff --git a/rollup.config.mjs b/rollup.config.mjs index 23fcac4b4e..6681c84f88 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -15,6 +15,7 @@ import { } from './tools/rollup/core-components-resolver.mjs'; import ignoreCss from './tools/rollup/ignore-css.mjs'; import processCss from './tools/rollup/process-css.mjs'; +import inlineThemes from './tools/rollup/inline-themes.mjs'; import coreComponentsTypingsResolver from './tools/rollup/core-components-typings-resolver.mjs'; import createPackageJson from './tools/rollup/create-package-json.mjs'; import { compiledDarkmodeGenerator } from './tools/rollup/compiled-darkmode-generator.mjs'; @@ -127,6 +128,7 @@ const es5 = { }), json(), postcssPlugin, + inlineThemes(), assetsCopyPlugin('dist'), copy({ flatten: false, targets: [{ src: ['**/package.json'], dest: 'dist' }] }), sourceCopyPlugin, @@ -165,6 +167,7 @@ const modern = { }), json(), postcssPlugin, + inlineThemes(), assetsCopyPlugin('dist/modern'), ], }; @@ -273,6 +276,7 @@ const esm = { }), json(), postcssPlugin, + inlineThemes(), assetsCopyPlugin('dist/esm'), ], }; @@ -326,4 +330,4 @@ const configs = ( ] ).filter(Boolean); -export default configs; \ No newline at end of file +export default configs; diff --git a/tools/rollup/inline-themes.mjs b/tools/rollup/inline-themes.mjs new file mode 100644 index 0000000000..a0706e25d0 --- /dev/null +++ b/tools/rollup/inline-themes.mjs @@ -0,0 +1,26 @@ +import fs from 'fs/promises'; +import path from 'path'; + +/* Плагин генерации js файлов для подключения тем */ +export default function inlineThemes() { + return { + name: 'inline-themes', + async transform(_, id) { + if (/\/packages\/themes\/src\/[^/]+\.ts/.test(id)) { + const theme = id.split('/').pop().split('.')[0]; + + const cssContent = await fs.readFile( + path.resolve(path.dirname(id), `../dist/${theme}.css`), + 'utf8', + ); + + return { + code: `export default \`${cssContent}\``, + map: { mappings: '' }, + }; + } + + return null; + }, + }; +}