Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbbd98fc

Browse files
committed
feat: support 3.3 imported types hmr
1 parent8407cf6 commitbbd98fc

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

‎src/pluginWebpack4.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { clientCache, typeDepToSFCMap } from './resolveScript'
55
importfs= require('fs')
66
import{compilerasvueCompiler}from'./compiler'
77
import{descriptorCache}from'./descriptorCache'
8+
import{needHMR}from'./util'
89

910
constRuleSet=require('webpack/lib/RuleSet')
1011

@@ -117,16 +118,11 @@ class VueLoaderPlugin {
117118
...rules,
118119
]
119120

120-
// 3.3 HMR support
121-
constisServer=
122-
vueLoaderOptions.isServerBuild??compiler.options.target==='node'
123-
constisProduction=
124-
compiler.options.mode==='production'||
125-
process.env.NODE_ENV==='production'
126-
constneedsHotReload=
127-
!isServer&&!isProduction&&vueLoaderOptions.hotReload!==false
128-
129-
if(needsHotReload&&vueCompiler.invalidateTypeCache){
121+
// 3.3 HMR support for imported types
122+
if(
123+
needHMR(vueLoaderOptions,compiler.options)&&
124+
vueCompiler.invalidateTypeCache
125+
){
130126
letwatcher:any
131127

132128
constWatchPack=require('watchpack')

‎src/pluginWebpack5.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import*asqsfrom'querystring'
22
importtype{VueLoaderOptions}from'./'
33
importtype{RuleSetRule,Compiler}from'webpack'
4+
import{needHMR}from'./util'
5+
import{clientCache,typeDepToSFCMap}from'./resolveScript'
6+
import{compilerasvueCompiler}from'./compiler'
7+
import{descriptorCache}from'./descriptorCache'
48

59
constid='vue-loader-plugin'
610
constNS='vue-loader'
@@ -225,6 +229,43 @@ class VueLoaderPlugin {
225229
...clonedRules,
226230
...rules,
227231
]
232+
233+
// 3.3 HMR support for imported types
234+
if(
235+
needHMR(vueLoaderOptions,compiler.options)&&
236+
vueCompiler.invalidateTypeCache
237+
){
238+
compiler.hooks.afterCompile.tap(id,(compilation)=>{
239+
if(compilation.compiler===compiler){
240+
for(constfileoftypeDepToSFCMap.keys()){
241+
compilation.fileDependencies.add(file)
242+
}
243+
}
244+
})
245+
compiler.hooks.watchRun.tap(id,()=>{
246+
if(!compiler.modifiedFiles)return
247+
for(constfileofcompiler.modifiedFiles){
248+
vueCompiler.invalidateTypeCache(file)
249+
constaffectedSFCs=typeDepToSFCMap.get(file)
250+
if(affectedSFCs){
251+
for(constsfcofaffectedSFCs){
252+
// bust script resolve cache
253+
constdesc=descriptorCache.get(sfc)
254+
if(desc)clientCache.delete(desc)
255+
// force update importing SFC
256+
//@ts-ignore
257+
compiler.fileTimestamps.set(sfc,{
258+
safeTime:Date.now(),
259+
timestamp:Date.now(),
260+
})
261+
}
262+
}
263+
}
264+
for(constfileofcompiler.removedFiles){
265+
vueCompiler.invalidateTypeCache(file)
266+
}
267+
})
268+
}
228269
}
229270
}
230271

‎src/util.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
importtype{LoaderContext}from'webpack'
1+
importtype{Compiler,LoaderContext}from'webpack'
22
importtype{SFCDescriptor,CompilerOptions}from'vue/compiler-sfc'
33
importtype{VueLoaderOptions}from'.'
44
import*aspathfrom'path'
55

6+
exportfunctionneedHMR(
7+
vueLoaderOptions:VueLoaderOptions,
8+
compilerOptions:Compiler['options']
9+
){
10+
constisServer=
11+
vueLoaderOptions.isServerBuild??compilerOptions.target==='node'
12+
constisProduction=
13+
compilerOptions.mode==='production'||
14+
process.env.NODE_ENV==='production'
15+
return!isServer&&!isProduction&&vueLoaderOptions.hotReload!==false
16+
}
17+
618
exportfunctionresolveTemplateTSOptions(
719
descriptor:SFCDescriptor,
820
options:VueLoaderOptions

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp