Skip to content

Commit 4a57a82

Browse files
committed
build(rspack): migrate from webpack css-loader to rspack built-in css
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
1 parent 1d22e6f commit 4a57a82

1 file changed

Lines changed: 7 additions & 33 deletions

File tree

rspack.config.js

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { CssExtractRspackPlugin, LightningCssMinimizerRspackPlugin, DefinePlugin,
1010
const NodePolyfillPlugin = require('@rspack/plugin-node-polyfill')
1111
const browserslist = require('browserslist')
1212
const path = require('node:path')
13-
const { VueLoaderPlugin } = require('vue-loader')
13+
const { VueLoaderPlugin } = require('rspack-vue-loader')
1414

1515
// browserslist-rs does not support baseline queries yet
1616
// Manually resolving the browserslist config to the list of browsers with minimal versions
@@ -60,6 +60,8 @@ module.exports = defineConfig((env) => {
6060
path: path.resolve('./js'),
6161
filename: `${appName}-[name].js?v=[contenthash]`,
6262
chunkFilename: `${appName}-[name].js?v=[contenthash]`,
63+
cssFilename: `../css/${appName}-[name].css?v=[contenthash]`,
64+
cssChunkFilename: `../css/chunks/${appName}-[name].css?v=[contenthash]`,
6365
// Set publicPath via __webpack_public_path__
6466
publicPath: 'auto',
6567
// We are working with .wasm and .tflite files as resources on a public path: it must be with the original name in the output folder's root
@@ -123,41 +125,19 @@ module.exports = defineConfig((env) => {
123125
rules: [
124126
{
125127
test: /\.vue$/,
126-
loader: 'vue-loader',
128+
loader: 'rspack-vue-loader',
127129
options: {
128130
experimentalInlineMatchResource: true,
129131
},
130132
},
131133
{
132134
test: /\.css$/,
133-
use: [
134-
{
135-
loader: CssExtractRspackPlugin.loader,
136-
},
137-
'css-loader',
138-
],
135+
type: 'css',
139136
},
140137
{
141138
test: /\.scss$/,
142-
use: [
143-
{
144-
loader: CssExtractRspackPlugin.loader,
145-
},
146-
'css-loader',
147-
{
148-
loader: 'sass-loader',
149-
options: {
150-
sassOptions: {
151-
// Sass emits BOM for CSS files with non-ASCII characters in production build by default
152-
// PostCSS (used in css-loader and Vue SFC compiler) starting from v8.5.24 stops removing BOM
153-
// Merging these styles keeps BOM in the middle of the file, breaking the first selector of each merged stylesheet
154-
// Disabling charset prevents breaking styles (a workaround until css-loader is fixed for the new PostCSS)
155-
// This is safe since the document has "<meta charset="utf-8">" anyway
156-
charset: false,
157-
},
158-
},
159-
},
160-
],
139+
type: 'css',
140+
use: ['sass-loader'],
161141
},
162142
{
163143
test: /\.ts$/,
@@ -237,12 +217,6 @@ module.exports = defineConfig((env) => {
237217
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
238218
}),
239219

240-
new CssExtractRspackPlugin({
241-
filename: '../css/talk-[name].css',
242-
chunkFilename: '../css/chunks/[id].chunk.css',
243-
ignoreOrder: true,
244-
}),
245-
246220
process.env.RSDOCTOR && new RsdoctorRspackPlugin(),
247221
],
248222

0 commit comments

Comments
 (0)