Skip to content

Commit

Permalink
Merge pull request #1 from WalkerKnapp/master
Browse files Browse the repository at this point in the history
Add an onlinePath Argument
  • Loading branch information
mentaljam authored Jan 20, 2020
2 parents a755e5d + 67b5fc1 commit e043e6a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ minify: {
},
```

### onlinePath

```js
string
```

A path to append to file references injected. This is useful for putting files on a CDN after building.

#### Example
```js
onlinePath: '//www.example.com/foo',
```
Which will generate:
```html
<script src="//www.example.com/foo/main.js"></script>
```

## License

[MIT](LICENSE) © [Petr Tsymbarovich](mailto:[email protected])
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ interface IPluginOptions {
preload?: string[] | Set<string>
modules?: boolean
minify?: false | MinifyOptions
onlinePath?: string
}

const enum Cache {
Expand Down Expand Up @@ -175,6 +176,7 @@ export default ({
preload,
modules,
minify: minifyOptions,
onlinePath: onlinePath,
...options
}: IPluginOptions): Plugin => ({
name: 'html2',
Expand Down Expand Up @@ -329,12 +331,12 @@ consider to use the esm format or switch off the option`)
const {name, ext} = path.parse(fileName)
const injectType = ext.slice(1)
if (name in entries) {
injectCSSandJS('/' + fileName, injectType, inject)
injectCSSandJS((onlinePath === undefined ? '' : onlinePath) + '/' + fileName, injectType, inject)
} else if (name in dynamicEntries && (preload as Set<string>).has(dynamicEntries[name])) {
const linkType = extensionToType(injectType)
if (linkType) {
addNewLine(head)
head.appendChild(new HTMLElement('link', {}, `rel="preload" href="/${fileName}" as="${linkType}"`))
head.appendChild(new HTMLElement('link', {}, `rel="preload" href="${(onlinePath === undefined ? '' : onlinePath)}/${fileName}" as="${linkType}"`))
}
}
})
Expand Down

0 comments on commit e043e6a

Please sign in to comment.