-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved everything related with public folder to publicFolderPlugin
- Loading branch information
Showing
5 changed files
with
56 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { Plugin } from "esbuild"; | ||
import { config, connections } from "../config.js"; | ||
import { jsAndTsRegex, notJsAndTsRegex, transformers } from "../../actions/start/transformers.js"; | ||
import { syncDirs } from "../../utils/syncDirs.js"; | ||
import { copy } from "../../utils/copy.js"; | ||
|
||
export const publicFolderPlugin: Plugin = { | ||
name: "michijs-dev-server-public-folder", | ||
setup(build) { | ||
// Copy public path - Omit to copy service worker - will be transformed after | ||
if (build.initialOptions.outdir) | ||
copy( | ||
config.public.path, | ||
build.initialOptions.outdir, | ||
transformers, | ||
[jsAndTsRegex], | ||
); | ||
|
||
let firstLoad = true; | ||
build.onEnd(() => { | ||
// first-load sw - Omit to copy any other non-js file | ||
if (firstLoad && build.initialOptions.outdir) { | ||
copy( | ||
config.public.path, | ||
build.initialOptions.outdir, | ||
transformers, | ||
[notJsAndTsRegex], | ||
); | ||
if (config.watch) | ||
syncDirs( | ||
config.public.path, | ||
config.esbuildOptions.outdir, | ||
transformers, | ||
undefined, | ||
undefined, | ||
(event, fileChangedPath) => { | ||
connections.forEach((x) => | ||
x.write( | ||
`event: change\ndata: ${JSON.stringify({ | ||
added: [], | ||
removed: event === "remove" ? [fileChangedPath] : [], | ||
updated: event === "update" ? [fileChangedPath] : [], | ||
})}\n\n`, | ||
), | ||
); | ||
}, | ||
); | ||
firstLoad = false; | ||
} | ||
}); | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters