Skip to content
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

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

Open
raphet opened this issue Sep 1, 2020 · 3 comments
Open

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

raphet opened this issue Sep 1, 2020 · 3 comments

Comments

@raphet
Copy link

raphet commented Sep 1, 2020

	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
Copy link

ierhyna commented Feb 9, 2021

Hi, any updates on this issue?

@mentaljam
Copy link
Owner

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

@mentaljam
Copy link
Owner

mentaljam commented Jul 8, 2021

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants