1919 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020 */
2121
22+ import { unlink } from 'fs'
2223import * as path from 'path'
2324import copy from 'rollup-plugin-copy'
2425import outputManifest , { KeyValueDecorator , OutputManifestParam } from 'rollup-plugin-output-manifest'
2526import { ConfigEnv , defineConfig , loadEnv , UserConfigExport } from 'vite'
2627
28+ const publicDir = 'public'
29+ const manifestFile = 'manifest.json'
2730const assets = {
2831 base : 'resources' ,
2932 scripts : 'resources/scripts' ,
@@ -56,7 +59,7 @@ export default defineConfig(({ mode }: ConfigEnv) => {
5659 build : {
5760 sourcemap : 'inline' ,
5861 manifest : false ,
59- outDir : 'public' ,
62+ outDir : publicDir ,
6063 assetsDir : '' ,
6164 rollupOptions : {
6265 input : {
@@ -68,7 +71,7 @@ export default defineConfig(({ mode }: ConfigEnv) => {
6871 } ,
6972 plugins : [
7073 outputManifest ( {
71- fileName : 'manifest.json' ,
74+ fileName : manifestFile ,
7275 generate :
7376 ( keyValueDecorator : KeyValueDecorator , seed : object , opt : OutputManifestParam ) => chunks =>
7477 chunks . reduce ( ( manifest , { name, fileName } ) => {
@@ -114,15 +117,15 @@ export default defineConfig(({ mode }: ConfigEnv) => {
114117 targets : [
115118 {
116119 src : path . resolve ( __dirname , `${ assets . base } /images/**/*` ) ,
117- dest : 'public /images'
120+ dest : ` ${ publicDir } /images`
118121 } ,
119122 {
120123 src : path . resolve ( __dirname , `${ assets . base } /svg/**/*` ) ,
121- dest : 'public /svg'
124+ dest : ` ${ publicDir } /svg`
122125 } ,
123126 {
124127 src : path . resolve ( __dirname , `${ assets . base } /fonts/**/*` ) ,
125- dest : 'public /fonts'
128+ dest : ` ${ publicDir } /fonts`
126129 }
127130 ]
128131 } )
@@ -137,6 +140,10 @@ export default defineConfig(({ mode }: ConfigEnv) => {
137140 const protocol = 'http'
138141 const https = ! ! ( devServerConfig . HMR_HTTPS_KEY && devServerConfig . HMR_HTTPS_CERT )
139142
143+ unlink ( `${ publicDir } /${ manifestFile } ` , error =>
144+ console . log ( `🧹 Wipe ${ manifestFile } :` , error ? `No ${ manifestFile } in the public directory` : '✅' )
145+ )
146+
140147 devServerConfig . HMR_HOST && ( host = devServerConfig . HMR_HOST )
141148 devServerConfig . HMR_PORT && ( port = parseInt ( devServerConfig . HMR_PORT ) )
142149
0 commit comments