-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
914 additions
and
153 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,29 @@ | ||
import WebpackChain from 'webpack-chain' | ||
import { applyRule } from './util' | ||
|
||
function after(rule: WebpackChain.Rule): void { | ||
} | ||
|
||
export default (config: WebpackChain): void => { | ||
const { cssmodule } = config.sasoConfig | ||
const isProd = config.toConfig().mode === 'production' | ||
|
||
const rule = config.module.rule('compile scss').test(/\.css$/) | ||
rule.exclude.add(/\.module/) | ||
|
||
const ruleWithModules = config.module.rule('compile scss with module').test(/\.module\.css$/) | ||
|
||
applyRule({ | ||
rule: ruleWithModules, | ||
config, | ||
isCssModules: true, | ||
after, | ||
}) | ||
|
||
applyRule({ | ||
rule, | ||
config, | ||
isCssModules: false, | ||
after | ||
}) | ||
} |
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,127 @@ | ||
import * as path from 'path' | ||
|
||
import FixStyleOnlyEntriesPlugin from 'webpack-fix-style-only-entries' | ||
import MiniCssExtractPlugin from 'mini-css-extract-plugin' | ||
import { SasoPlugin } from '../../typings/compiler' | ||
import WebpackChain from 'webpack-chain' | ||
import { cosmiconfigSync } from 'cosmiconfig' | ||
|
||
const plugin: SasoPlugin = { | ||
apply(compiler) { | ||
compiler.hook('beforeCompile', (config: WebpackChain) => { | ||
/** | ||
* @type {import('webpack-chain')} | ||
*/ | ||
const c = config | ||
const { cssmodule } = c.sasoConfig | ||
const isProd = c.toConfig().mode === 'production' | ||
const postcssConfig = cosmiconfigSync('postcss', { | ||
stopDir: process.cwd() | ||
}).search() | ||
|
||
const cssRule = c.module.rule('compile css').test(/\.css$/) | ||
const sassRule = c.module.rule('compile sass').test(/\.s[a|c]ss$/) | ||
const lessRule = c.module.rule('compile less').test(/\.less$/) | ||
const stylusRule = c.module.rule('compile stylus').test(/\.styl(us)?$/) | ||
|
||
const postcssOptions = { | ||
config: { | ||
path: postcssConfig ? path.dirname(postcssConfig.filepath) : path.resolve(__dirname, '../../config') | ||
} | ||
} | ||
|
||
if (!isProd) { | ||
cssRule.use('vue-style-loader').loader(require.resolve('vue-style-loader')) | ||
sassRule.use('vue-style-loader').loader(require.resolve('vue-style-loader')) | ||
lessRule.use('vue-style-loader').loader(require.resolve('vue-style-loader')) | ||
stylusRule.use('vue-style-loader').loader(require.resolve('vue-style-loader')) | ||
} else { | ||
cssRule.use('css-mini-css').loader(MiniCssExtractPlugin.loader) | ||
sassRule.use('sass-mini-css').loader(MiniCssExtractPlugin.loader) | ||
lessRule.use('less-mini-css').loader(MiniCssExtractPlugin.loader) | ||
stylusRule.use('stylus-mini-css').loader(MiniCssExtractPlugin.loader) | ||
} | ||
|
||
if (cssmodule) { | ||
cssRule.use('typings-for-css-modules-loader').loader(require.resolve('typings-for-css-modules-loader')).options({ | ||
modules: true, | ||
namedExport: true, | ||
camelCase: true, | ||
localIdentName: '[local]--[hash:base64:5]', | ||
}) | ||
sassRule.use('typings-for-css-modules-loader').loader(require.resolve('typings-for-css-modules-loader')).options({ | ||
modules: true, | ||
namedExport: true, | ||
camelCase: true, | ||
localIdentName: '[local]--[hash:base64:5]', | ||
}) | ||
lessRule.use('typings-for-css-modules-loader').loader(require.resolve('typings-for-css-modules-loader')).options({ | ||
modules: true, | ||
namedExport: true, | ||
camelCase: true, | ||
localIdentName: '[local]--[hash:base64:5]', | ||
}) | ||
stylusRule.use('typings-for-css-modules-loader').loader(require.resolve('typings-for-css-modules-loader')).options({ | ||
modules: true, | ||
namedExport: true, | ||
camelCase: true, | ||
localIdentName: '[local]--[hash:base64:5]', | ||
}) | ||
} else { | ||
// set css-loader | ||
cssRule.use('css-loader').loader(require.resolve('css-loader')) | ||
sassRule.use('css-loader').loader(require.resolve('css-loader')).options({ | ||
sourceMap: true, | ||
importLoaders: 1 | ||
}) | ||
lessRule.use('css-loader').loader(require.resolve('css-loader')) | ||
stylusRule.use('css-loader').loader(require.resolve('css-loader')) | ||
} | ||
|
||
// set postcss | ||
cssRule.use('css-postcss-loader').loader(require.resolve('postcss-loader')).options(postcssOptions) | ||
|
||
sassRule.use('sass-postcss-loader').loader(require.resolve('postcss-loader')).options(postcssOptions) | ||
|
||
lessRule.use('less-postcss-loader').loader(require.resolve('postcss-loader')).options(postcssOptions) | ||
|
||
stylusRule.use('stylus-postcss-loader').loader(require.resolve('postcss-loader')).options(postcssOptions) | ||
|
||
// set sass-loader | ||
sassRule.use('resolve-url-loader').loader(require.resolve('resolve-url-loader')).options({ | ||
sourceMap: true, | ||
keepQuery: true, | ||
debug: false | ||
}) | ||
|
||
sassRule | ||
.use('sass-loader') | ||
.loader(require.resolve('sass-loader')) | ||
.options({ | ||
sourceMap: true, | ||
sourceMapContents: false, | ||
implementation: require('sass') | ||
}) | ||
.end() | ||
|
||
// set less-loader | ||
lessRule.use('less-loader').loader(require.resolve('less-loader')).end() | ||
|
||
// set stylus-loader | ||
stylusRule.use('stylus-loader').loader(require.resolve('stylus-loader')).end() | ||
const { fileHash, extraCss } = config.sasoConfig | ||
const prodFileName = fileHash ? '[name].[hash].css' : '[name].css' | ||
if (extraCss) { | ||
c.plugin('extra css').use(MiniCssExtractPlugin, [ | ||
{ | ||
filename: isProd ? prodFileName : '[name].css' | ||
} | ||
]) | ||
|
||
c.plugin('fix style entry').use(FixStyleOnlyEntriesPlugin) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export default plugin |
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,33 @@ | ||
import * as path from 'path' | ||
|
||
import FixStyleOnlyEntriesPlugin from 'webpack-fix-style-only-entries' | ||
import MiniCssExtractPlugin from 'mini-css-extract-plugin' | ||
import { SasoPlugin } from '../../typings/compiler' | ||
import WebpackChain from 'webpack-chain' | ||
import { cosmiconfigSync } from 'cosmiconfig' | ||
import sassRule from './sass' | ||
|
||
const plugin: SasoPlugin = { | ||
apply(compiler) { | ||
compiler.hook('beforeCompile', (config: WebpackChain) => { | ||
/** | ||
* @type {import('webpack-chain')} | ||
*/ | ||
const isProd = config.toConfig().mode === 'production' | ||
sassRule(config) | ||
const { fileHash, extraCss } = config.sasoConfig | ||
const prodFileName = fileHash ? '[name].[hash].css' : '[name].css' | ||
if (extraCss) { | ||
config.plugin('extra css').use(MiniCssExtractPlugin, [ | ||
{ | ||
filename: isProd ? prodFileName : '[name].css' | ||
} | ||
]) | ||
|
||
config.plugin('fix style entry').use(FixStyleOnlyEntriesPlugin) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export default plugin |
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,30 @@ | ||
import WebpackChain from 'webpack-chain' | ||
import { applyRule } from './util' | ||
|
||
function after(rule: WebpackChain.Rule): void { | ||
rule.use('less-loader').loader(require.resolve('less-loader')).end() | ||
} | ||
|
||
export default (config: WebpackChain): void => { | ||
const { cssmodule } = config.sasoConfig | ||
const isProd = config.toConfig().mode === 'production' | ||
|
||
const rule = config.module.rule('compile scss').test(/\.less$/) | ||
rule.exclude.add(/\.module/) | ||
|
||
const ruleWithModules = config.module.rule('compile scss with module').test(/\.module\.less$/) | ||
|
||
applyRule({ | ||
rule: ruleWithModules, | ||
config, | ||
isCssModules: true, | ||
after, | ||
}) | ||
|
||
applyRule({ | ||
rule, | ||
config, | ||
isCssModules: false, | ||
after | ||
}) | ||
} |
Oops, something went wrong.