mentaljam / rollup-plugin-html2

Rollup plugin to inject bundled files to an HTML template
https://www.npmjs.com/package/rollup-plugin-html2
MIT License
20 stars 5 forks source link

index.html written in same folder like bundle.js #12

Open raphet opened 3 years ago

raphet commented 3 years ago
    output: {
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js'
    },
    plugins: [
        html2({
            template: 'src/template.html',
            fileName: 'index.html',
            externals: [{ file: 'build/bundle.css', pos:  'before' }]
        }),

Structure - wanted: /src/template.html /public/index.html /public/build/bundle.js /public/build/bundle.css

Structure - given: /src/template.html /public/build/index.html /public/build/bundle.js /public/build/bundle.css

In other words, this script stores index.html in the same folder as the bundle.js but I would like to store it one folder up. How would I set this?

ierhyna commented 3 years ago

Hi, any updates on this issue?

mentaljam commented 3 years ago

Hi, sorry but I cannot maintain this repo any more...

mentaljam commented 2 years ago

You can try to achieve the desired placement of files by setting output.entryFileNames and output.chunkFileNames:

const fileNames = 'build/[name].js'

export default {
  output: {
    entryFileNames: fileNames,
    chunkFileNames: fileNames,
    // Other options
  }
  // Other options
}

However, all the assets (for example generated CSS files) will be placed near your generated html file. To place these files to the build subdir you can define the output.assetFileNames as function:

const fileNames = 'build/[name].js'

export default {
  output: {
    entryFileNames: fileNames,
    chunkFileNames: fileNames,
    assetFileNames({fileName}) {
      return fileName !== 'index.html' ? ('build/' + fileName) : fileName
    }
    // Other options
  }
  // Other options
}