Specify the output location of the html entry file.
npm install rollup-plugin-html-location -D
Assuming the project structure is as follows:
/
├─src
│ ├─demo
│ │ ├─demo1
│ │ │ └─index.html
│ │ └─demo2
│ │ └─index.html
│ └─main.js
├─package.json
├─rollup.config.js
└─...
// rollup.config.js
export default {
input: {
demo1: 'src/demo1/index.html',
demo2: 'src/demo2/index.html',
main: 'main.js',
},
output: {
dir: 'dist',
entryFileNames: '[name].js',
},
};
Output:
├─dist
│ ├─src
│ │ ├─demo1
│ │ │ └─index.html
│ │ └─demo2
│ │ └─index.html
│ └─main.js
└─...
// rollup.config.js
import HTMLLocation from 'rollup-plugin-html-location';
export default {
input: {
demo1: 'src/demo1/index.html',
demo2: 'src/demo2/index.html',
main: 'main.js',
},
output: {
dir: 'dist',
entryFileNames: '[name].js',
},
plugins: [
HTMLLocation({
dir: 'result',
}),
],
};
Output:
├─dist
│ ├─result
│ │ └─src
│ │ ├─demo1
│ │ │ └─index.html
│ │ └─demo2
│ │ └─index.html
│ └─main.js
└─...
// rollup.config.js
import HTMLLocation from 'rollup-plugin-html-location';
export default {
input: {
demo1: 'src/demo1/index.html',
demo2: 'src/demo2/index.html',
main: 'main.js',
},
output: {
dir: 'dist',
entryFileNames: '[name].js',
},
plugins: [
HTMLLocation({
filename: {
'src/demo1/index.html': 'result/demo1.html'
'src/demo2/index.html': 'result/demo2.html'
}
})
],
};
Output:
├─dist
│ ├─result
│ │ ├─demo1.html
│ │ └─demo2.html
│ └─main.js
└─...
// rollup.config.js
import HTMLLocation from 'rollup-plugin-html-location';
export default {
input: {
demo1: 'src/demo1/index.html',
demo2: 'src/demo2/index.html',
main: 'main.js',
},
output: {
dir: 'dist',
entryFileNames: '[name].js',
},
plugins: [
HTMLLocation({
filename: input => input.replace('src/', ''),
}),
],
};
Output:
├─dist
│ ├─demo1
│ │ └─index.html
│ ├─demo2
│ │ └─index.html
│ └─main.js
└─...
// rollup.config.js
import HTMLLocation from 'rollup-plugin-html-location';
export default {
input: {
demo1: 'src/demo1/index.html',
demo2: 'src/demo2/index.html',
main: 'main.js',
},
output: {
dir: 'dist',
entryFileNames: '[name].js',
},
plugins: [
HTMLLocation({
filename: {
'src/demo1/index.html': 'demo1.html'
'src/demo2/index.html': 'demo2.html'
},
disableClearEmptyFolder: true,
}),
],
};
Output:
├─dist
│ ├─src
│ │ ├─demo1
│ │ └─demo2
│ ├─demo1.html
│ ├─demo2.html
│ └─main.js
└─...
// rollup.config.js
import HTMLLocation from 'rollup-plugin-html-location';
export default {
input: {
demo1: 'src/demo1/index.html',
demo2: 'src/demo2/index.html',
main: 'main.js',
},
output: {
dir: 'dist',
entryFileNames: '[name].js',
},
plugins: [
HTMLLocation({
filename: {
'src/demo1/index.html': 'demo1.html'
'src/demo2/index.html': 'demo2.html'
},
logging: true,
}),
],
};
Print operation log:
html-location: [src/demo1/index.html] ==> [demo1.html]
html-location: [src/demo2/index.html] ==> [demo2.html]
html-location: clear empty folder!