Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taro-webpack-runner): add miniCssExtractLoaderOption support #5922

Merged
merged 2 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/config-detail.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,23 @@ stylus-loader 的附加配置。配置项参考[官方文档](https://github.com
}
```

### h5.miniCssExtractLoaderOption

`mini-css-extract-plugin` 的loader配置,在 `enableExtract` 为 `true` 的情况下生效。与 `miniCssExtractPluginOption` 选项配合使用。
可以配置对应的loader config,配置项参考[官方文档](https://github.com/webpack-contrib/mini-css-extract-plugin),例如:

```jsx
{
miniCssExtractPluginOption: {
filename: 'css/[name].css',
chunkFilename: 'css/[id].css'
},
miniCssExtractLoaderOption: {
publicPath: '../'
}
}
```

### h5.module

配置一些 H5 端用到的插件模块配置,暂时只有 `postcss`。
Expand Down
1 change: 1 addition & 0 deletions packages/taro-webpack-runner/src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('Regs', () => {
fontUrlLoaderOption: {},
imageUrlLoaderOption: {},
mediaUrlLoaderOption: {},
miniCssExtractLoaderOption: {},
esnextModules: [],

module: {
Expand Down
2 changes: 2 additions & 0 deletions packages/taro-webpack-runner/src/config/dev.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
imageUrlLoaderOption = emptyObj,

miniCssExtractPluginOption = emptyObj,
miniCssExtractLoaderOption = emptyObj,
esnextModules = [],

module = {
Expand Down Expand Up @@ -116,6 +117,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
fontUrlLoaderOption,
imageUrlLoaderOption,
mediaUrlLoaderOption,
miniCssExtractLoaderOption,
esnextModules,

module,
Expand Down
2 changes: 2 additions & 0 deletions packages/taro-webpack-runner/src/config/prod.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
mediaUrlLoaderOption = emptyObj,
fontUrlLoaderOption = emptyObj,
imageUrlLoaderOption = emptyObj,
miniCssExtractLoaderOption = emptyObj,

miniCssExtractPluginOption = emptyObj,
esnextModules = [],
Expand Down Expand Up @@ -137,6 +138,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {
fontUrlLoaderOption,
imageUrlLoaderOption,
mediaUrlLoaderOption,
miniCssExtractLoaderOption,
esnextModules,

module,
Expand Down
8 changes: 5 additions & 3 deletions packages/taro-webpack-runner/src/util/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ const getLessLoader = pipe(mergeOption, partial(getLoader, 'less-loader'))
const getStylusLoader = pipe(mergeOption, partial(getLoader, 'stylus-loader'))
const getBabelLoader = pipe(mergeOption, partial(getLoader, 'babel-loader'))
const getUrlLoader = pipe(mergeOption, partial(getLoader, 'url-loader'))
const getExtractCssLoader = () => {
const getExtractCssLoader = (options) => {
return {
loader: MiniCssExtractPlugin.loader
loader: MiniCssExtractPlugin.loader,
options: options || {}
}
}

Expand Down Expand Up @@ -245,6 +246,7 @@ const getModule = (appPath: string, {
fontUrlLoaderOption,
imageUrlLoaderOption,
mediaUrlLoaderOption,
miniCssExtractLoaderOption,
esnextModules = [] as (string | RegExp)[],

module,
Expand Down Expand Up @@ -316,7 +318,7 @@ const getModule = (appPath: string, {
styleLoaderOption
])

const extractCssLoader = getExtractCssLoader()
const extractCssLoader = getExtractCssLoader(miniCssExtractLoaderOption)

const lastStyleLoader = enableExtract ? extractCssLoader : styleLoader

Expand Down
1 change: 1 addition & 0 deletions packages/taro-webpack-runner/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface TaroH5Config {
fontUrlLoaderOption: Option;
imageUrlLoaderOption: Option;
miniCssExtractPluginOption: Option;
miniCssExtractLoaderOption: Option;
esnextModules: string[];

module?: {
Expand Down