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

fix(mini-runner): 开发模式修改文件会刷新所有json,导致开发工具加载过慢 #6951

Open
wants to merge 6 commits into
base: 2.x
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export default class MiniPlugin {
this.context = compiler.context
this.appEntry = this.getAppEntry(compiler)
let taroLoadChunksPlugin
let changedFiles
const commonStyles: Set<string> = new Set()
const {
commonChunks,
Expand Down Expand Up @@ -269,7 +270,7 @@ export default class MiniPlugin {
compiler.hooks.watchRun.tapAsync(
PLUGIN_NAME,
this.tryAsync(async (compiler: webpack.Compiler) => {
const changedFiles = this.getChangedFiles(compiler)
changedFiles = this.getChangedFiles(compiler)
if (!changedFiles.length) {
await this.run(compiler)
} else {
Expand Down Expand Up @@ -343,7 +344,7 @@ export default class MiniPlugin {
PLUGIN_NAME,
this.tryAsync(async compilation => {
compilation.errors = compilation.errors.concat(this.errors)
await this.generateMiniFiles(compilation, commonStyles)
await this.generateMiniFiles(compilation, commonStyles, changedFiles)
this.addedComponents.clear()
})
)
Expand Down Expand Up @@ -915,12 +916,12 @@ export default class MiniPlugin {
})
}

async generateMiniFiles (compilation: webpack.compilation.Compilation, commonStyles: Set<string>) {
async generateMiniFiles (compilation: webpack.compilation.Compilation, commonStyles: Set<string>, changedFiles: Array<string>) {
const { isBuildQuickapp, fileType, buildAdapter, commonChunks, modifyBuildTempFileContent, modifyBuildAssets, isBuildPlugin } = this.options
if (typeof modifyBuildTempFileContent === 'function') {
await modifyBuildTempFileContent(taroFileTypeMap)
}
Object.keys(taroFileTypeMap).forEach(item => {
(changedFiles.length ? changedFiles : Object.keys(taroFileTypeMap)).forEach(item => {
const relativePath = this.getRelativePath(item)
const extname = path.extname(item)
let jsonPath = relativePath.replace(extname, fileType.config).replace(/\\/g, '/').replace(/^\//, '')
Expand Down