Permalink
Browse files

feat(task): refine relative url for `assetsUrlPrefix`

  • Loading branch information...
sparanoid committed Sep 23, 2018
1 parent be18873 commit 10a3831484d54ebe76dec35cbaf0f1c59e1ae35e
Showing with 16 additions and 2 deletions.
  1. +16 −2 tasks/assets_inline.js
@@ -102,6 +102,17 @@ module.exports = function(grunt) {
}
};
var calckAssetsBase = function(path) {
if (!path) {
return "";
}
if (path.endsWith('/')) {
return path;
} else {
return path + '/';
}
}
this.files.forEach(function(filePair) {
// Check that the source file exists
if (filePair.src.length === 0) { return; }
@@ -193,7 +204,9 @@ module.exports = function(grunt) {
} else {
var filePath = (style.substr(0, 1) === "/") ? path.resolve(options.cssDir, style.substr(1)) : path.join(path.dirname(filePair.src.toString()), style);
styles_dom_link_stylesheets[i].outerHTML = options.cssTags.start + grunt.file.read(filePath).replace(/(\.{2}\/)+/g, options.assetsUrlPrefix) + options.cssTags.end;
var assetsBase = calckAssetsBase(options.assetsUrlPrefix);
styles_dom_link_stylesheets[i].outerHTML = options.cssTags.start + grunt.file.read(filePath).replace(/(\.{2}\/)+/g, assetsBase) + options.cssTags.end;
var deleteFlag = (' (will keep)').gray;
if (deleteOriginal) {
@@ -230,9 +243,10 @@ module.exports = function(grunt) {
}
var filePath = (script.substr(0, 1) === "/") ? path.resolve(options.jsDir, script.substr(1)) : path.join(path.dirname(filePair.src.toString()), script);
var assetsBase = calckAssetsBase(options.assetsUrlPrefix);
//create and replace script with new scipt tag
scripts_dom[i].outerHTML = options.jsTags.start + uglifyJS(grunt.file.read(filePath).replace(/(\.{2}\/)+/g, options.assetsUrlPrefix)) + options.jsTags.end;
scripts_dom[i].outerHTML = options.jsTags.start + uglifyJS(grunt.file.read(filePath).replace(/(\.{2}\/)+/g, assetsBase)) + options.jsTags.end;
var deleteFlag = (' (will keep)').gray;
if (deleteOriginal) {

0 comments on commit 10a3831

Please sign in to comment.