-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: prevent building public files #117
base: main
Are you sure you want to change the base?
Conversation
Is this only an issue in dev mode? What happens on build? |
updated
process.env.NODE_ENV === 'development' ? 'foo.js' : 'public/foo.js' maybe we should also ignore public files from here.
|
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. |
This function will return vite-plugin-web-extension/src/utils/loader.ts Lines 57 to 66 in 600cb8b
|
@@ -177,6 +178,12 @@ export default abstract class DevBuilder< | |||
} | |||
|
|||
protected async writeManifestScriptFile(fileName: string): Promise<string> { | |||
const publicDirName = path.basename(this.publicDir); | |||
if (fileName.split(path.sep)[0] === publicDirName) { | |||
await copy(fileName, `${this.outDir}/${fileName}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this copy need to happen? Wouldn't all public files have already been copied by line 67?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is necessary because their behaviors are different.
line 67: public/foo.js
-> dist/foo.js
this line: public/foo.js
-> dist/public/foo.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok. Line 67 is correct. The contents of public are supposed to be copied to the root of the dist directory not a subdirectory [1] so we wouldn't want this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we include public/foo.js
in the content scripts section of the manifest, it will not be found.
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.