Skip to content

Commit

Permalink
fix: 修复混合开发模式下小程序页面没有引入全局样式的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanzebin authored and Chen-jj committed Aug 11, 2021
1 parent ea34d5d commit f6e3e90
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import { ConcatSource } from 'webpack-sources'
import { promoteRelativePath, META_TYPE, } from '@tarojs/helper'
import { promoteRelativePath, META_TYPE } from '@tarojs/helper'

const path = require('path')

const wxssReg = /.*\.wxss$/

export default ctx => {
ctx.modifyBuildAssets(({ assets }) => {
if (!ctx.runOpts.options.blended) return

Object.keys(assets).forEach(filename => {
const isWxss = wxssReg.test(filename)

if (isWxss && filename !== 'app.wxss') {
const source = new ConcatSource()
const originSource = assets[filename].source()
const relativePath = JSON.stringify(promoteRelativePath(path.relative(filename, 'app.wxss')))

source.add(`@import ${relativePath};`)
source.add('\n')
source.add(originSource)
assets[filename] = {
size: () => source.source().length,
source: () => source.source()
}
}
})
})

ctx.onCompilerMake(({ compilation }) => {
if (!ctx.runOpts.options.blended) return

Expand Down

0 comments on commit f6e3e90

Please sign in to comment.