diff options
Diffstat (limited to 'node_modules/@vue/component-compiler-utils/dist/templateCompilerModules/assetUrl.js')
| -rw-r--r-- | node_modules/@vue/component-compiler-utils/dist/templateCompilerModules/assetUrl.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/node_modules/@vue/component-compiler-utils/dist/templateCompilerModules/assetUrl.js b/node_modules/@vue/component-compiler-utils/dist/templateCompilerModules/assetUrl.js new file mode 100644 index 00000000..ef95f951 --- /dev/null +++ b/node_modules/@vue/component-compiler-utils/dist/templateCompilerModules/assetUrl.js @@ -0,0 +1,44 @@ +"use strict"; +// vue compiler module for transforming `<tag>:<attribute>` to `require` +Object.defineProperty(exports, "__esModule", { value: true }); +const utils_1 = require("./utils"); +const defaultOptions = { + video: ['src', 'poster'], + source: 'src', + img: 'src', + image: ['xlink:href', 'href'] +}; +exports.default = (userOptions) => { + const options = userOptions + ? Object.assign({}, defaultOptions, userOptions) + : defaultOptions; + return { + postTransformNode: (node) => { + transform(node, options); + } + }; +}; +function transform(node, options) { + for (const tag in options) { + if ((tag === '*' || node.tag === tag) && node.attrs) { + const attributes = options[tag]; + if (typeof attributes === 'string') { + node.attrs.some(attr => rewrite(attr, attributes)); + } + else if (Array.isArray(attributes)) { + attributes.forEach(item => node.attrs.some(attr => rewrite(attr, item))); + } + } + } +} +function rewrite(attr, name) { + if (attr.name === name) { + const value = attr.value; + // only transform static URLs + if (value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') { + attr.value = utils_1.urlToRequire(value.slice(1, -1)); + return true; + } + } + return false; +} |
