Skip to content

Commit

Permalink
fix(mini-runner): 修复引用原生组件编译后样式文件缺失的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 7, 2020
1 parent 0632783 commit cd0f55a
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ITaroFileInfo {
config: IConfig,
template?: string,
code?: string,
style?: string,
taroSelfComponents?: Set<{
name: string,
path: string
Expand Down Expand Up @@ -690,6 +691,10 @@ export default class MiniPlugin {
template,
code
}
if (isNative) {
const stylePath = this.getStylePath(file.path)
if (fs.existsSync(stylePath)) taroFileTypeMap[file.path]['style'] = fs.readFileSync(stylePath).toString()
}
if (isQuickApp && taroSelfComponents) {
taroFileTypeMap[file.path].taroSelfComponents = new Set(Array.from(taroSelfComponents).map(item => {
const taroJsQuickAppComponentsPath = getTaroJsQuickAppComponentsPath(this.options.nodeModulesPath)
Expand Down Expand Up @@ -809,6 +814,12 @@ export default class MiniPlugin {
source: () => template
}
}
if (itemInfo.style) {
compilation.assets[stylePath] = {
size: () => itemInfo.style!.length,
source: () => itemInfo.style
}
}
if (itemInfo.taroSelfComponents) {
itemInfo.taroSelfComponents.forEach(item => {
if (fs.existsSync(item.path)) {
Expand Down Expand Up @@ -842,18 +853,18 @@ export default class MiniPlugin {

this.quickappStyleFiles.forEach(item => {
if (fs.existsSync(item.path)) {
const styleContent = fs.readFileSync(item.path).toString()
let relativePath
if (NODE_MODULES_REG.test(item.path)) {
relativePath = item.path.replace(this.context, '').replace(/node_modules/gi, 'npm').replace(/\\\\/g, '/')
}
else {
relativePath = item.path.replace(this.sourceDir, '').replace(/\\\\/g, '/')
}
compilation.assets[relativePath] = {
size: () => styleContent.length,
source: () => styleContent
}
const styleContent = fs.readFileSync(item.path).toString()
let relativePath
if (NODE_MODULES_REG.test(item.path)) {
relativePath = item.path.replace(this.context, '').replace(/node_modules/gi, 'npm').replace(/\\\\/g, '/')
}
else {
relativePath = item.path.replace(this.sourceDir, '').replace(/\\\\/g, '/')
}
compilation.assets[relativePath] = {
size: () => styleContent.length,
source: () => styleContent
}
}
})
}
Expand Down

0 comments on commit cd0f55a

Please sign in to comment.