vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.53k stars 6.19k forks source link

Add `publicDir` Config #232

Closed bekalshenoy closed 4 years ago

bekalshenoy commented 4 years ago

Is your feature request related to a problem? Please describe. I Want Content Of public In Root Of dist Instead Of In Public Folder Inside dist.

Describe the solution you'd like Add An Option To Configure publicDir Relative To outDir.

Describe alternatives you've considered Instead Of Creating Public Folder In dist Add It's Content To dist.

underfin commented 4 years ago

The build command has a option assetsDir,maybe can help you.

bekalshenoy commented 4 years ago

No, I Have package.json In Public Folder, To Use In Build. I Use This package.json To Build Electron Application. I Can Use A Node Script To Do This( Running Script Containing fs After vite build) But It Would Be Cleaner And I Can Use A Modified package.json Instead Of Copying, If Have A Option To Change Path Of Public Folder In Build.

underfin commented 4 years ago

Look like this case isn't relate of vite build.Can you explain in detail with the publicDir intention for vite build.I'm not sure get it.

bekalshenoy commented 4 years ago

In Vue cli Content Inside Public Folder Will Go To dist\ But In Vite It Is In dist\public\. I Want Vue cli Behavior Here.

yyx990803 commented 4 years ago

If you import it as /public/ in your code, then the directory should be copied to the exact same location in the dist dir, otherwise the paths will be incorrect. It is intentional to make this not configurable.

hjbdev commented 4 years ago

@yyx990803 Laravel uses the public/ directory as the folder it serves from, by not making the public path configurable, this means Vite will never work with Laravel. Unless I'm misunderstanding something?

My outDir must be set to public or built files won't be accessible on the frontend, but this throws an error

Error: Source and destination must not be the same.
    at C:\Users\harry\Sites\vite-laravel\node_modules\vite\node_modules\fs-extra\lib\util\stat.js:39:17
    at cb (util.js:196:39)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

Which is understandable, but being able to rename vite's public folder would then enable this to work?

hjbdev commented 4 years ago

Nevermind, changing the root config option allowed me to shift this into a separate folder. Sorry about that.