samrum / vite-plugin-web-extension

A vite plugin for generating cross browser platform, ES module based web extensions.
MIT License
323 stars 33 forks source link

feat: prevent building public files #117

Open maltoze opened 1 year ago

maltoze commented 1 year ago

I have a pre-compiled js file under public folder, which is included in the content_scripts of the manifest file. However, writeBuild will overwrite it.

samrum commented 1 year ago

Is this only an issue in dev mode? What happens on build?

maltoze commented 1 year ago

updated

using this in my manifest.😂

process.env.NODE_ENV === 'development' ? 'foo.js' : 'public/foo.js'

maybe we should also ignore public files from here. https://github.com/samrum/vite-plugin-web-extension/blob/600cb8b294e8cdfc44bccb7d3c50275a8c447486/src/devBuilder/devBuilder.ts#L179

then there is no need to check NODE_ENV and use public/foo.js directly.

samrum commented 1 year ago

Yeah, I think that'll be the more correct solution. All of the write functions shouldn't be writing anything that exists in the public directory. Similarly for the build functions.

maltoze commented 1 year ago

This function will return null when building. It seems that we only need to focus on dev mode. https://github.com/samrum/vite-plugin-web-extension/blob/600cb8b294e8cdfc44bccb7d3c50275a8c447486/src/utils/loader.ts#L57-L66