diff --git a/lib/loader.js b/lib/loader.js index 09834d1..76b9473 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -266,13 +266,14 @@ module.exports = function () { try { options = JSON.parse(_fs2.default.readFileSync(_path2.default.resolve(process.cwd(), '.babelrc'), 'utf-8')); } catch (e) { - options = { compact: false }; + options = { compact: false, presets: ['es2015'] }; } return options; }(); // babelCode :: String -> String + babelCode = function babelCode(content) { return es6 ? babel.transform(content, babelRc).code : content; }; @@ -351,12 +352,12 @@ module.exports = function () { // finalUrl :: String - finalUrl = (query.base || '') + '/' + pathname('[name].[ext]'); + finalUrl = (query.base ? query.base + '/' : '') + pathname('[name].[ext]'); // webpackModuleResult :: String -> String webpackModuleResult = function webpackModuleResult(url) { - return ['\t\t\t', 'var link = document.createElement(\'link\');', 'link.rel = \'import\';', 'link.href = ' + JSON.stringify(finalUrl) + ';', 'document.head.appendChild(link)'].join('\n\t\t\t'); + return ['\t\t\t', 'var link = document.createElement(\'link\');', 'link.rel = \'import\';', 'link.href = __webpack_public_path__ + ' + JSON.stringify(finalUrl) + ';', 'document.head.appendChild(link)'].join('\n\t\t\t'); }; // --------------------- diff --git a/src/loader.js b/src/loader.js index c1a5a48..82e86de 100644 --- a/src/loader.js +++ b/src/loader.js @@ -119,7 +119,7 @@ module.exports = async function main(content) { try { options = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), '.babelrc'), 'utf-8')) } catch(e) { - options = {compact: false} + options = {compact: false, presets: ['es2015']} } return options })() @@ -162,7 +162,7 @@ module.exports = async function main(content) { } // finalUrl :: String - const finalUrl = (query.base || '') + '/' + pathname('[name].[ext]') + const finalUrl = (query.base ? query.base + '/' : '') + pathname('[name].[ext]') // webpackModuleResult :: String -> String const webpackModuleResult = (url) => ( @@ -170,7 +170,7 @@ module.exports = async function main(content) { '\t\t\t', 'var link = document.createElement(\'link\');', 'link.rel = \'import\';', - 'link.href = ' + JSON.stringify(finalUrl) + ';', + 'link.href = __webpack_public_path__ + ' + JSON.stringify(finalUrl) + ';', 'document.head.appendChild(link)', // 'module.exports = __webpack_public_path__ + ' + JSON.stringify(url), ].join('\n\t\t\t')