Skip to content

Commit

Permalink
chore: enable addWatchFile
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Aug 22, 2024
1 parent 5342ac5 commit 9b2eb75
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
4 changes: 1 addition & 3 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
// raw requests, read from disk
if (rawRE.test(id)) {
const file = checkPublicFile(id, config) || cleanUrl(id)
if (config.command !== 'build') {
this.addWatchFile(file)
}
this.addWatchFile(file)
// raw query, read file and return as string
return {
code: `export default ${JSON.stringify(
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
moduleCache.set(id, modules)
}

if (deps && !isBuild) {
if (deps) {
for (const file of deps) {
this.addWatchFile(file)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/loadFallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export function loadFallbackPlugin(): Plugin {
try {
const cleanedId = cleanUrl(id)
const content = await fsp.readFile(cleanedId, 'utf-8')
// this.addWatchFile(cleanedId)
this.addWatchFile(cleanedId)
return content
} catch (e) {
const content = await fsp.readFile(id, 'utf-8')
// this.addWatchFile(id)
this.addWatchFile(id)
return content
}
},
Expand Down
8 changes: 3 additions & 5 deletions playground/transform-plugin/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ let transformCount = 1
const transformPlugin = {
name: 'transform',
load(id) {
if (id === file && typeof this.addWatchFile === 'function') {
if (id === file) {
// Ensure `index.js` is reloaded if 'plugin-dep-load.js' is changed
this.addWatchFile('./plugin-dep-load.js')
}
},
transform(code, id) {
if (id === file) {
if (typeof this.addWatchFile === 'function'){
// Ensure `index.js` is reevaluated if 'plugin-dep.js' is changed
this.addWatchFile('./plugin-dep.js')
}
// Ensure `index.js` is reevaluated if 'plugin-dep.js' is changed
this.addWatchFile('./plugin-dep.js')

return `
// Inject TRANSFORM_COUNT
Expand Down

0 comments on commit 9b2eb75

Please sign in to comment.