Closed phiphou closed 3 years ago
renderChunk
and will only take effect during build.Solved with a custom rollup plugin :
const bannerPlugin = (banner) => {
return {
name: 'banner',
async writeBundle (NULL, bundle) {
for (const fileName of Object.entries(bundle)) {
const file = fileName[0]
const extRegex = new RegExp(/\.(css|js)$/i)
const vendorRegex = new RegExp(/vendor/)
if (extRegex.test(file) && !vendorRegex.test(file)) {
let data = fs.readFileSync(`./dist/${file}`, { encoding: 'utf8' })
data = `/* ${banner} */ ${data}`
fs.writeFileSync(`./dist/${file}`, data)
}
}
}
}
}
build: {
rollupOptions: {
plugins: [
bannerPlugin('Your banner')
]
}
}
Solved with a custom rollup plugin :
const bannerPlugin = (banner) => { return { name: 'banner', async writeBundle (NULL, bundle) { for (const fileName of Object.entries(bundle)) { const file = fileName[0] const extRegex = new RegExp(/\.(css|js)$/i) const vendorRegex = new RegExp(/vendor/) if (extRegex.test(file) && !vendorRegex.test(file)) { let data = fs.readFileSync('./dist/' + file, { encoding: 'utf8' }) data = `/* ${banner} */ ${data}` fs.writeFileSync('./dist/' + file, data) } } } } } build: { rollupOptions: { plugins: [ bannerPlugin('Your banner') ] } }
Nice! Thanks for your solution!
⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.
Describe the bug
I'm trying to use rollup-plugin-banner2, added it the the rollup plugins in rollupOptions but I dont'see the banner. Is there a default rollup config option that override it ? Also tried with rollup-plugin-banner but with no luck.
Reproduction
https://github.com/stropho/rollup-plugin-banner2
System Info
vite
version: 2.0.0-beta.12