Skip to content

Commit

Permalink
fix(mini-runner): 修复小程序编译时样式中引用静态资源转换为 base64
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Dec 26, 2019
1 parent b60782f commit 6dcade6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/taro-mini-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"ora": "^3.4.0",
"postcss-loader": "^3.0.0",
"postcss-pxtransform": "2.0.0-beta.4",
"postcss-url": "^8.0.0",
"request": "^2.88.0",
"resolve": "^1.11.1",
"sass-loader": "^7.1.0",
Expand Down
14 changes: 13 additions & 1 deletion packages/taro-mini-runner/src/webpack/postcss.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as path from 'path'

import * as autoprefixer from 'autoprefixer'
import * as pxtransform from 'postcss-pxtransform'
import * as url from 'postcss-url'
import { sync as resolveSync } from 'resolve'
import { IPostcssOption } from '@tarojs/taro/types/compile'

Expand All @@ -24,6 +25,14 @@ const defaultPxtransformOption: {
}
}

const defaultUrlOption = {
enable: true,
config: {
limit: 1000,
url: 'inline'
}
}

const optionsWithDefaults = ['autoprefixer', 'pxtransform', 'cssModules', 'url']

const plugins = [] as any[]
Expand All @@ -45,14 +54,17 @@ export const getPostcssPlugins = function (appPath: string, {

const autoprefixerOption = recursiveMerge({}, defaultAutoprefixerOption, postcssOption.autoprefixer)
const pxtransformOption = recursiveMerge({}, defaultPxtransformOption, postcssOption.pxtransform)

const urlOption = recursiveMerge({}, defaultUrlOption, postcssOption.url)
if (autoprefixerOption.enable) {
plugins.push(autoprefixer(autoprefixerOption.config))
}

if (pxtransformOption.enable && !isQuickapp) {
plugins.push(pxtransform(pxtransformOption.config))
}
if (urlOption.enable) {
plugins.push(url(urlOption.config))
}

Object.entries(postcssOption).forEach(([pluginName, pluginOption]) => {
if (optionsWithDefaults.indexOf(pluginName) > -1) return
Expand Down

0 comments on commit 6dcade6

Please sign in to comment.