Skip to content

Commit

Permalink
Merge pull request #1814 from didi/fix-rn-cssnano
Browse files Browse the repository at this point in the history
feat: add default cssnano preset options in the RN environment
  • Loading branch information
hiyuki authored Jan 15, 2025
2 parents 3ce41dc + 30e0f85 commit 46821e5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/webpack-plugin/lib/wxss/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ const {
} = require('./utils')
const createHelpers = require('../helpers')

const RN_PRESET_OPTIMISATION = {
reduceInitial: false,
normalizeWhitespace: false,
minifyFontValues: false,
convertValues: false
}

module.exports = async function loader (content, map, meta) {
const rawOptions = this.getOptions(schema)
const plugins = []
Expand All @@ -41,6 +48,7 @@ module.exports = async function loader (content, map, meta) {
const externals = mpx.externals
const root = mpx.projectRoot
const sourceMap = mpx.cssSourceMap || false
const isRN = ['ios', 'android', 'harmony'].includes(mpx.mode)

let options

Expand Down Expand Up @@ -152,12 +160,17 @@ module.exports = async function loader (content, map, meta) {
if (this.minimize) {
const cssnano = require('cssnano')
const minimizeOptions = rawOptions.minimize || {}
const presetOptimisation = Object.assign(
{},
isRN ? RN_PRESET_OPTIMISATION : {},
minimizeOptions.optimisation
)
let cssnanoConfig = {
preset: ['cssnano-preset-default', minimizeOptions.optimisation || {}]
preset: ['cssnano-preset-default', presetOptimisation]
}
if (minimizeOptions.advanced) {
cssnanoConfig = {
preset: ['cssnano-preset-advanced', minimizeOptions.optimisation || {}]
preset: ['cssnano-preset-advanced', presetOptimisation]
}
}
plugins.push(cssnano(cssnanoConfig))
Expand Down

0 comments on commit 46821e5

Please sign in to comment.