Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
fix(docz-plugin-css): css modules applied logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 23, 2018
1 parent e04452e commit c5fa378
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions packages/docz-plugin-css/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import { getLocalIdent } from './get-local-ident'
* Tests
*/

const tests: Record<string, RegExp> = {
postcss: /\.css$/,
'module-postcss': /\.module\.css$/,
sass: /\.s(a|c)ss$/,
'module-sass': /\.module\.s(a|c)ss$/,
less: /\.less$/,
'module-less': /\.module\.less$/,
stylus: /\.styl(us)?$/,
'module-stylus': /\.module\.styl(us)?$/,
type PreProcessor = 'postcss' | 'sass' | 'less' | 'stylus'
const tests: Record<PreProcessor, RegExp> = {
postcss: /(\.module)?\.css$/,
sass: /(\.module)?\.s(a|c)ss$/,
less: /(\.module)?\.less$/,
stylus: /(\.module)?\.styl(us)?$/,
}

/**
Expand Down Expand Up @@ -88,11 +85,6 @@ const applyRule = (
) => {
const { preprocessor = 'postcss', cssOpts, loaderOpts } = opts

const regexp = tests[preprocessor]
const modulesRegexp = tests[`module-${preprocessor}`]
const test = cssmodules ? modulesRegexp : regexp
const exclude = [/node_modules/]

const loaderfn = loaders[preprocessor]
const loader = loaderfn(loaderOpts)
const cssoptions = merge(cssOpts, {
Expand All @@ -103,8 +95,8 @@ const applyRule = (
})

return {
test,
exclude: cssmodules ? exclude : exclude.concat([modulesRegexp]),
test: tests[preprocessor],
exclude: [/node_modules/],
use: loader(cssoptions, dev),
}
}
Expand All @@ -119,10 +111,7 @@ export interface CSSPluginOptions {
export const css = (opts: CSSPluginOptions) =>
createPlugin({
modifyBundlerConfig: (config, dev) => {
config.module.rules.push(
applyRule(opts, false, dev),
applyRule(opts, opts.cssmodules, dev)
)
config.module.rules.push(applyRule(opts, opts.cssmodules, dev))

if (!dev) {
const test = tests[opts.preprocessor || 'postcss']
Expand Down

0 comments on commit c5fa378

Please sign in to comment.