gulp-resolve-import
[]
Used to import file content using grammar: '<link rel = "import" href = "filepath">'. It supports multi-level imports and automatically adjust the resource reference path to be relative to the containing html file. The <img>, <audio>, <video>, <script>, <source> and <src-placeholder> tags, and inline style background url are supported.
Usage
- Declare imports in your file
/a.html
/sub/b.jsref.html
/sub/sub2/c.jsref.html
- Specify the action in the build script.
var gulp = resolveImport = ; gulp;
The resulting html for a.html will be like:
Supported source declaration
For html, this plugin currently handle the following html tags and corresponding attribute names to dynamically adjust the asset references:
link
-href
script
-src
img
-src
audio
-src
video
-src
source
-src
src-placeholder
-src
You can use src-placeholder
tag to let this plugin help manage the source that you may need to dynamically assign asset source, like:
var audioObj = document; var extNameAndTypes = "ogg": "audio/ogg" "m4a": "audio/mpeg" "mp3": "audio/mpeg" ; "ogg" "m4a" "mp3";
For css, keyword url
is used to identify potential asset reference.
Options
baseAbsolutePath {String}
Used as the base path to determine the final relative path of referring resources. Default to be the folder of the processing file.
prependText {String}
The text to be prepended while resolving imports. Default to be an empty string.
linkMetaFilter {Function}
The filter method is used to select imports to resolve, i.e., resolve imports conditionally. The method takes 1 argument of type: {LinkMeta} which has the following methods:
- {Boolean}
hasAttribute({String} name)
. Test if the<link>
tag has the specified attribute. - {String}
getAttribute({String} name)
. Get the specified attribute value.
linkMetaFilter_applyRecursively {Boolean}
Specify whether or not apply the filter method in the resolved import content. Default to be true.
License
MIT