build(styleguidist): add support for CSS Modules

Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
This commit is contained in:
Grigorii K. Shartsev 2024-02-09 17:33:43 +01:00
Родитель 593ef01f3b
Коммит 8ec50780c8
1 изменённых файлов: 41 добавлений и 18 удалений

Просмотреть файл

@ -20,27 +20,50 @@ const SCOPE_VERSION = JSON.stringify(versionHash)
webpackConfig.devtool = isDev ? false : 'source-map' webpackConfig.devtool = isDev ? false : 'source-map'
const sassLoader = {
loader: 'sass-loader',
options: {
additionalData: `@use 'sass:math'; $scope_version:${SCOPE_VERSION}; @import 'variables'; @import 'material-icons';`,
/**
* ! needed for resolve-url-loader
*/
sourceMap: true,
sassOptions: {
sourceMapContents: false,
includePaths: [
path.resolve(__dirname, './src/assets'),
],
},
},
}
webpackRules.RULE_SCSS = { webpackRules.RULE_SCSS = {
test: /\.scss$/, test: /\.scss$/,
use: [ oneOf: [
'style-loader',
'css-loader',
'resolve-url-loader',
{ {
loader: 'sass-loader', resourceQuery: /module/,
options: { use: [
additionalData: `@use 'sass:math'; $scope_version:${SCOPE_VERSION}; @import 'variables'; @import 'material-icons';`, 'style-loader',
/** {
* ! needed for resolve-url-loader loader: 'css-loader',
*/ options: {
sourceMap: true, modules: {
sassOptions: { // Same as in Vite
sourceMapContents: false, localIdentName: '_[local]_[hash:base64:5]',
includePaths: [ },
path.resolve(__dirname, './src/assets'), },
],
}, },
}, 'resolve-url-loader',
sassLoader,
],
},
{
use: [
'style-loader',
'css-loader',
'resolve-url-loader',
sassLoader,
],
}, },
], ],
} }
@ -61,7 +84,7 @@ webpackRules.RULE_NODE_MJS = {
type: 'javascript/auto', type: 'javascript/auto',
resolve: { resolve: {
fullySpecified: false, fullySpecified: false,
} },
} }
webpackConfig.module.rules = Object.values(webpackRules) webpackConfig.module.rules = Object.values(webpackRules)