-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a0f0f3
commit f527aa0
Showing
7 changed files
with
728 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.