Skip to content

Commit

Permalink
fix(online path): Change option name form prefix to onlinePath and fi…
Browse files Browse the repository at this point in the history
…x slash issue
  • Loading branch information
MonFig committed Sep 5, 2019
1 parent d4c715d commit abf5e48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export default {
You will find both bundle and map files are hashed and placed in your `dist/foo` folder:
`bundle-76bf4fb5dbbd62f0fa3708aa3d8a9350.js`, `bundle-84e0f899735b1e320e625c9a5c7c49a7.js.map`

## prefix
## onlinePath

You can set 'prefix' as anything like `//www.sohu.com/` if you want to put the files on CDN after building.
You can set 'onlinePath' as anything like `//www.sohu.com/` if you want to put the files on CDN after building.

```js
{
Expand All @@ -91,7 +91,7 @@ You can set 'prefix' as anything like `//www.sohu.com/` if you want to put the f
html({
dest: "dist/foo",
// ...
prefix: '//www.sohu.com/dist/foo'
onlinePath: '//www.sohu.com/dist/foo'
})
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
template: 'src/index.html',
filename: 'index.html',
dest: "dist/",
prefix: '//www.sohu.com/test/',
onlinePath: '//www.sohu.com/test/',
// inject: 'head',
externals: [
{ type: 'js', file: 'https://test.js', inject: 'head' }
Expand Down
8 changes: 4 additions & 4 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, absolute, ignore, prefix } = opt;
const { template, filename, externals, inject, dest, absolute, ignore, onlinePath } = opt;

return {
name: 'html',
Expand Down Expand Up @@ -96,10 +96,10 @@ export default (opt = {}) => {


let src = isURL(file) ? file : absolutePathPrefix + relative(destDir, file).replace(/\\/g, '/');
if (prefix) {
if (onlinePath) {
const filename = file.split('/').slice(-1)[0];
const divide = filename.slice(-1) === '/' ? '' : '/';
src = prefix + divide + filename;
const slash = onlinePath.slice(-1) === '/' ? '' : '/';
src = onlinePath + slash + filename;
}
if (node.timestamp) {
src += '?t=' + (new Date()).getTime();
Expand Down

0 comments on commit abf5e48

Please sign in to comment.