Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(themes): inline themes to js files #1400

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-pumas-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alfalab/core-components-themes": patch
---

Импорт JS-файла темы больше не зависит от webpack-лоадера. Теперь содержимое темы представлено в виде строки.
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 @@ -119,6 +120,7 @@ const es5 = {
plugins: [
...baseConfig.plugins,
multiInputPlugin,
inlineThemes(),
typescript({
tsconfig: (resolvedConfig) => ({
...resolvedConfig,
Expand Down Expand Up @@ -155,6 +157,7 @@ const modern = {
plugins: [
...baseConfig.plugins,
multiInputPlugin,
inlineThemes(),
typescript({
outDir: 'dist/modern',
tsconfig: (resolvedConfig) => ({
Expand Down Expand Up @@ -264,6 +267,7 @@ const esm = {
plugins: [
...baseConfig.plugins,
multiInputPlugin,
inlineThemes(),
typescript({
outDir: 'dist/esm',
tsconfig: (resolvedConfig) => ({
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;
},
};
}
Loading