Skip to content

Commit

Permalink
feat: use rspack (#7249)
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereCloud authored Oct 22, 2024
1 parent 272b3f9 commit 43a6605
Show file tree
Hide file tree
Showing 7 changed files with 835 additions and 262 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"@csstools/postcss-global-data": "3.0.0",
"@playwright/experimental-ct-react": "1.48.1",
"@playwright/test": "1.48.1",
"@rspack/cli": "^v1.0.11",
"@rspack/core": "^v1.0.11",
"@size-limit/file": "^11.1.6",
"@size-limit/webpack": "^11.1.6",
"@size-limit/webpack-css": "^11.1.6",
Expand All @@ -36,6 +38,7 @@
"@vkontakte/stylelint-config": "^4.1.0",
"@vkontakte/vkui-tokens": "4.55.0",
"autoprefixer": "^10.4.20",
"clean-webpack-plugin": "^4.0.0",
"concurrently": "^9.0.1",
"cross-env": "^7.0.3",
"css-loader": "^7.1.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/vkui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"clear": "yarn run -T shx rm -rf dist/* || yarn run -T shx true",
"docker:clear-playwright-cache": "../../scripts/generate_env_docker.sh && docker compose --env-file=./.env.docker rm -f && docker volume rm vkui_package_vkui_playwright_cache",
"postcss": "yarn run -T cross-env NODE_ENV=production concurrently 'yarn:postcss:*'",
"postcss:bundle": "yarn run -T webpack --config webpack.styles.config.js",
"postcss:bundle": "yarn run -T rspack --config rspack.styles.config.ts",
"postcss:modules": "yarn run -T postcss './src/**/*.css' --base ./src --dir ./dist/cssm --config ./cssm",
"swc-base": "yarn run -T cross-env NODE_ENV=production swc src/ --config-file package.swcrc --extensions .tsx,.jsx,.ts,.js --strip-leading-paths",
"swc:es6": "yarn swc-base -d dist -s",
Expand Down Expand Up @@ -85,6 +85,7 @@
"devDependencies": {
"@storybook/react": "8.3.6",
"@storybook/react-webpack5": "8.3.6",
"@types/node": "*",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"storybook": "8.3.6",
Expand Down
113 changes: 113 additions & 0 deletions packages/vkui/rspack.styles.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import path from 'node:path';
import rspack, { type Configuration, type RspackPluginInstance } from '@rspack/core';
import browserslist from 'browserslist';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import { makePostcssPlugins } from './scripts/postcss';

const rootDirectory = path.join(__dirname, '../../');
const browser = browserslist.readConfig(path.join(rootDirectory, '.browserslistrc'));

interface MakeCssRuleUseOptions {
/**
* Флаг для определения сборки css модулей
*/
isCssModulesFile?: boolean;
}

/**
* Конфигурация для css
*/
function makeCssRuleUse({ isCssModulesFile = false }: MakeCssRuleUseOptions = {}) {
return [
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: makePostcssPlugins({ isVKUIPackageBuild: true, isCssModulesFile }),
},
},
},
];
}

const config: Configuration = {
mode: 'production',
entry: {
vkui: ['./src/styles/themes.css', './src/index.ts'],
components: './src/index.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js.tmp',
cssFilename: '[name].css',
},
module: {
rules: [
{
sideEffects: true,
test: /\.[jt]sx?$/,
exclude: /node_modules/,
loader: 'builtin:swc-loader',
options: {
jsc: {
experimental: {
plugins: [
[
'swc-plugin-css-modules',
{
generate_scoped_name: 'vkui[folder]_[local]',
},
],
],
},
},
},
},
{
test: /\.css$/,
exclude: /\.module\.css$/,
use: makeCssRuleUse(),
type: 'css',
},
{
test: /\.module\.css$/,
use: makeCssRuleUse({ isCssModulesFile: true }),
type: 'css',
},
],
},
optimization: {
minimize: true,
minimizer: [
new rspack.LightningCssMinimizerRspackPlugin({
minimizerOptions: {
targets: browser.defaults,
},
}),
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
devtool: 'source-map',
plugins: [
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
protectWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [],
cleanAfterEveryBuildPatterns: ['*.tmp', '*.tmp.*'],
}) as unknown as RspackPluginInstance,
],
stats: {
all: false,
assets: true,
errors: true,
warnings: true,
},
experiments: {
css: true,
},
};

// eslint-disable-next-line import/no-default-export -- rspack-у нужен дефолтный экспорт
export default config;
12 changes: 6 additions & 6 deletions packages/vkui/scripts/postcss.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type postcss from 'postcss';

interface MakePostcssPluginsOptions {
isVKUIPackageBuild: boolean;
isProduction: boolean;
isCssModulesFile: boolean;
isESNext: boolean;
isStorybook: boolean;
disableMinimizer: boolean;
isVKUIPackageBuild?: boolean;
isProduction?: boolean;
isCssModulesFile?: boolean;
isESNext?: boolean;
isStorybook?: boolean;
disableMinimizer?: boolean;
}

export function makePostcssPlugins(options?: MakePostcssPluginsOptions): postcss.AcceptedPlugin[];
3 changes: 2 additions & 1 deletion packages/vkui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"playwright/index.tsx",
"scripts/*.js",
"scripts/*.mjs",
"./jest.*.ts"
"./jest.*.ts",
"*.config.ts"
],
"files": ["./global.d.ts", "types/env.d.ts"]
}
90 changes: 0 additions & 90 deletions packages/vkui/webpack.styles.config.js

This file was deleted.

Loading

0 comments on commit 43a6605

Please sign in to comment.