@lemon-clown-wpg/webpack-rule-css
v0.0.3
Published
css|stylus|sass rule of <webpack config>.module.rules
Downloads
5
Readme
Usage
Install
yarn add --dev @lemon-clown-wpg/webpack-rule-css
If you want to generate
*.d.ts
, moreoptionalDependencies
need to install:@teamsupercell/typings-for-css-modules-loader
If you want to support
*.styl
, moreoptionalDependencies
need to install:resolve-url-loader
stylus
stylus-loader
If you want to support
*.sass|*.scss
, moreoptionalDependencies
need to install:resolve-url-loader
node-sass
sass-loader
Use in webpack.config.js/webpack.config.ts
import path from 'path' import { calcCssRule, calcStylusRule, CssRuleProps, StylusRuleProps, } from '@lemon-clown-wpg/webpack-rule-css' const publicUrlOrPath = '/' const cssRuleOptions: CssRuleProps = { include: path.resolve('src'), isEnvDevelopment: process.env.NODE_ENV === 'development', isEnvProduction: process.env.NODE_ENV === 'production', shouldUseSourceMap: true, // optionals shouldGenerateDts: true, styleLoaderOptions: {} miniCssExtractLoaderOptions: { // assume css located in `static/css`, use '../../' to locate index.html folder // in production `publicUrlOrPath` can be a relative path publicPath: publicUrlOrPath.startsWith('.') ? undefined : '../../', }, cssLoaderOptions: { modules: { localIdentName: 'wpg-[local]' }, }, postcssLoaderOptions: {} } const stylusRuleOptions: StyleRuleProps = { ...cssRuleOptions, // optionals resolveUrlLoaderOptions: {}, stylusLoaderOptions: {}, } export default { ... module: { rules: [ ... { // "oneOf" will traverse all following loaders until one will // match the requirements. When no loader matches it will fall // back to the "file" loader at the end of the loader list. oneOf: [ ... // process *.css calcCssRule(cssRuleOptions), // process *.styl calcStylusRule(stylusRuleOptions), ... ] } ... ] } ... }
Options
calcCssRule
: see CssRulePropscalcStylusRule
: see StylusRulePropscalcSassRule
: see SassRuleProps