Skip to content

Commit

Permalink
feat(themes): inline themes to js files
Browse files Browse the repository at this point in the history
  • Loading branch information
reme3d2y committed Oct 1, 2024
1 parent b9e445a commit 360db5a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
4 changes: 0 additions & 4 deletions packages/themes/src/click.ts
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 0 additions & 4 deletions packages/themes/src/corp.ts
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 0 additions & 4 deletions packages/themes/src/dark.ts
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 0 additions & 4 deletions packages/themes/src/intranet.ts
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 0 additions & 4 deletions packages/themes/src/mobile.ts
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 0 additions & 4 deletions packages/themes/src/site.ts
Original file line number Diff line number Diff line change
@@ -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();
6 changes: 5 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -127,6 +128,7 @@ const es5 = {
}),
json(),
postcssPlugin,
inlineThemes(),
assetsCopyPlugin('dist'),
copy({ flatten: false, targets: [{ src: ['**/package.json'], dest: 'dist' }] }),
sourceCopyPlugin,
Expand Down Expand Up @@ -165,6 +167,7 @@ const modern = {
}),
json(),
postcssPlugin,
inlineThemes(),
assetsCopyPlugin('dist/modern'),
],
};
Expand Down Expand Up @@ -273,6 +276,7 @@ const esm = {
}),
json(),
postcssPlugin,
inlineThemes(),
assetsCopyPlugin('dist/esm'),
],
};
Expand Down Expand Up @@ -326,4 +330,4 @@ const configs = (
]
).filter(Boolean);

export default configs;
export default configs;
26 changes: 26 additions & 0 deletions tools/rollup/inline-themes.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
}

0 comments on commit 360db5a

Please sign in to comment.