fix(lib): ensure webpack inline loaders stay prefixed

when making a component path relative

fix https://github.com/nuxt/nuxt.js/issues/3314
This commit is contained in:
Hannes Diercks 2018-05-09 17:49:21 +02:00
parent 929817741b
commit c017da10f6
No known key found for this signature in database
GPG Key ID: 5EE4BD6DCE65A843
2 changed files with 18 additions and 0 deletions

View File

@ -153,6 +153,13 @@ export const relativeTo = function relativeTo() {
let args = Array.prototype.slice.apply(arguments) let args = Array.prototype.slice.apply(arguments)
let dir = args.shift() let dir = args.shift()
// Keep webpack inline loader intact
if (args[0].indexOf('!') !== -1) {
const loaders = args.shift().split('!')
return loaders.concat(relativeTo(dir, loaders.pop(), ...args)).join('!')
}
// Resolve path // Resolve path
let _path = r(...args) let _path = r(...args)

View File

@ -216,6 +216,17 @@ describe('utils', () => {
]) ])
expect(routes).toMatchObject([ '/login', '/about', '', '/post' ]) expect(routes).toMatchObject([ '/login', '/about', '', '/post' ])
}) })
describe('relativeTo', () => {
test('makes path relative to dir', () => {
expect(Utils.relativeTo('/foo/bar', '/foo/baz')).toBe('../baz')
})
test('keeps webpack inline loaders prepended', () => {
expect(Utils.relativeTo('/foo/bar', 'loader1!loader2!/foo/baz'))
.toBe('loader1!loader2!../baz')
})
})
}) })
test('createRoutes should allow snake case routes', () => { test('createRoutes should allow snake case routes', () => {