Skip to content

Commit

Permalink
Fixed URL for Chrome extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCoder committed Feb 19, 2021
1 parent 7d9aee1 commit 28c7ca3
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ export function loadJS(src) {
return d.promise;
}

function getUrl(relativeUrl) {
return chrome.extension
? chrome.extension.getURL(relativeUrl)
: `${
location.origin
}${BASE_PATH}/${relativeUrl}`
}

/* eslint-disable max-params */
export function getCompleteHtml(html, css, js, item, isForExport) {
Expand All @@ -326,7 +333,7 @@ export function getCompleteHtml(html, css, js, item, isForExport) {
.reduce(function(links, url) {
return (
links +
(url ? '\n<link rel="stylesheet" href="' + url + '"></link>' : '')
(url ? '\n<link rel="stylesheet" href="' + getUrl(url) + '"></link>' : '')
);
}, '');

Expand Down Expand Up @@ -355,20 +362,16 @@ export function getCompleteHtml(html, css, js, item, isForExport) {
'"></script>';
}
contents +=
'<script src="' + Vue + '"></script>';
'<script src="' + getUrl(Vue) + '"></script>';
contents +=
'<script src="' + Vuex + '"></script>';
'<script src="' + getUrl(Vuex) + '"></script>';
contents +=
'<script src="' + vueSequence + '"></script>';
'<script src="' + getUrl(vueSequence) + '"></script>';

if (item.jsMode === JsModes.ES6) {
contents +=
'<script src="' +
(chrome.extension
? chrome.extension.getURL('lib/transpilers/babel-polyfill.min.js')
: `${
location.origin
}${BASE_PATH}/lib/transpilers/babel-polyfill.min.js`) +
getUrl('lib/transpilers/babel-polyfill.min.js') +
'"></script>';
}

Expand Down

0 comments on commit 28c7ca3

Please sign in to comment.