Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/template-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module.exports = function (html) {

// prettify render fn
if (!isProduction) {
code = prettier.format(code, { semi: false })
code = prettier.format(code, { semi: false, parser: 'babylon' })
}

// mark with stripped (this enables Vue to use correct runtime proxy detection)
Expand Down
20 changes: 7 additions & 13 deletions lib/template-compiler/modules/transform-require.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// vue compiler module for transforming `<tag>:<attribute>` to `require`

const urlToRequire = require('../url-to-require')

const defaultOptions = {
video: ['src', 'poster'],
source: 'src',
Expand Down Expand Up @@ -34,19 +36,11 @@ function transform (node, options) {

function rewrite (attr, name) {
if (attr.name === name) {
let value = attr.value
const isStatic = value.charAt(0) === '"' && value.charAt(value.length - 1) === '"'
if (!isStatic) {
return
}
const firstChar = value.charAt(1)
if (firstChar === '.' || firstChar === '~') {
if (firstChar === '~') {
const secondChar = value.charAt(2)
value = '"' + value.slice(secondChar === '/' ? 3 : 2)
}
attr.value = `require(${value})`
const value = attr.value
// only transform static URLs
if (value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') {
attr.value = urlToRequire(value.slice(1, -1))
return true
}
return true
}
}
16 changes: 2 additions & 14 deletions lib/template-compiler/modules/transform-srcset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// vue compiler module for transforming `img:srcset` to a number of `require`s

const urlToRequire = require('../url-to-require')

module.exports = () => ({
postTransformNode: node => {
transform(node)
Expand Down Expand Up @@ -43,17 +45,3 @@ function transform (node) {
})
}
}

function urlToRequire (url) {
// same logic as in transform-require.js
const firstChar = url.charAt(0)
if (firstChar === '.' || firstChar === '~') {
if (firstChar === '~') {
const secondChar = url.charAt(1)
url = url.slice(secondChar === '/' ? 2 : 1)
}
return `require("${url}")`
} else {
return `"${url}"`
}
}
13 changes: 13 additions & 0 deletions lib/template-compiler/url-to-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function urlToRequire (url) {
// same logic as in transform-require.js
const firstChar = url.charAt(0)
if (firstChar === '.' || firstChar === '~' || firstChar === '@') {
if (firstChar === '~') {
const secondChar = url.charAt(1)
url = url.slice(secondChar === '/' ? 2 : 1)
}
return `require("${url}")`
} else {
return `"${url}"`
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
"version": "13.6.2",
"version": "13.7.0",
"description": "Vue single-file component loader for Webpack",
"main": "index.js",
"repository": {
Expand Down