Skip to content

Commit

Permalink
Add absolute path support for SPAs
Browse files Browse the repository at this point in the history
This closes @haifeng2013/rollup-plugin-bundle-html #8
  • Loading branch information
StevenWeathers committed May 19, 2019
1 parent 2d98d00 commit 3d65623
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function isURL(url){
}

export default (opt = {}) => {
const { template, filename, externals, inject, dest } = opt;
const { template, filename, externals, inject, dest, absolute } = opt;

return {
name: 'html',
Expand All @@ -44,6 +44,7 @@ export default (opt = {}) => {
const destPath = relative('./', fileName);
const destDir = dest || destPath.slice(0, destPath.indexOf(pathSeperator));
const destFile = `${destDir}/${filename || basename(template)}`;
const absolutePathPrefix = absolute ? '/' : '';

traverse(destDir, fileList);

Expand Down Expand Up @@ -89,7 +90,7 @@ export default (opt = {}) => {
writeFileSync(file, code);
}

let src = isURL(file) ? file : relative(destDir, file).replace(/\\/g, '/');
let src = isURL(file) ? file : absolutePathPrefix + relative(destDir, file).replace(/\\/g, '/');

if (node.timestamp) {
src += '?t=' + (new Date()).getTime();
Expand Down

0 comments on commit 3d65623

Please sign in to comment.