plugin-tools
plugin-tools copied to clipboard
Bug: `npm run build` duplicates `asset/resource`
Which package(s) does this bug affect?
- [X] Create Plugin
- [ ] Sign Plugin
- [ ] Plugin E2E
Package versions
4.0.1
What happened?
When building the plugin in dev or build mode, any *.svg (or likely other assets) will be duplicated in the dist/ directory - one set with "regular" or plain-text names, and another set with hashed names.
This behavior is because of webpack.config.ts's CopyWebpackPlugin function. I commented out a few of the // Optional lines. Look at the diff of my webpack.config.ts file to see how I fixed the problem:
https://github.com/nicfv/Psychart/compare/v4.0.6...v4.1.0#diff-735a1fddcd9112f2185fca9468f67db2ddb9a24c07186299c005dacefd18e5f5L152
HOWEVER, whenever you run npx @grafana/create-plugin update it reverts the contents of webpack.config.ts so this is not a great solution in the long run.
FURTHERMORE, commenting out those 2 optional lines isn't enough, because then in npm run build it hashes the names for all svg files, including logo.svg. This is a problem because package.json references the logo in plain text. So, to solve this, I had to add another line in the copy function to cherry-pick the file called img/logo.svg.
What you expected to happen
The dist/ directory should only contain the plain-text file names on npm run dev and hashed file names on npm run build. Neither script should create file duplicates in dist/
This is my build output after making the changes to webpack.config.ts and running npm run build. I manually copy over logo.svg, because I needed that one to be called logo.svg (not the hashed value) because the logo is referenced in package.json
Here is the contents of that same directory after running npm run dev (it nests the files under img/img, and I'm not sure why, but it still works. As you can see, logo.svg exists twice again, because of my cherry-pick):
How to reproduce it (as minimally and precisely as possible)
- Create a plugin
- Add files to
src/img/*.svg npm installnpm run build- Observe the
dist/directory
Environment
System:
OS: macOS 14.2.1
CPU: (8) arm64 Apple M2
Memory: 991.56 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.12.0 - /usr/local/bin/node
npm: 8.19.2 - /usr/local/bin/npm
Browsers:
Brave Browser: 121.1.62.165
Chrome: 105.0.5195.102
Firefox: 122.0
Safari: 17.2.1
Additional context
No response
@6nv thanks for reporting this issue and it can be indeed reproduced, we do not see this as something that we want to fix with a high priority right now as those cases are quite rare and even then it does not really breaks anything.