Skip to content

Commit 8e02b12

Browse files
committed
fix: fix backward compatibility of the as option
1 parent 399c0dc commit 8e02b12

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class PreloadPlugin {
7575
// then we need to set the 'as' attribute correctly.
7676
if (options.rel === 'preload') {
7777
attributes.as = determineAsValue({
78-
href: file,
78+
href,
79+
file,
7980
optionsAs: options.as
8081
})
8182

src/lib/determine-as-value.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const assert = require('assert')
1919
const path = require('path')
2020
const { URL } = require('url')
2121

22-
function determineAsValue ({ optionsAs, href }) {
22+
function determineAsValue ({ optionsAs, href, file }) {
2323
assert(href, `The 'href' parameter was not provided.`)
2424

2525
switch (typeof optionsAs) {
@@ -36,7 +36,9 @@ function determineAsValue ({ optionsAs, href }) {
3636
// value based on the suffix of filename.
3737

3838
// We only care about the pathname, so just use any domain when constructing the URL.
39-
const url = new URL(href, 'https://example.com')
39+
// Use file instead of href option because the publicPath part may be malformed.
40+
// See https://github.com/vuejs/vue-cli/issues/5672
41+
const url = new URL(file || href, 'https://example.com')
4042
const extension = path.extname(url.pathname)
4143

4244
if (extension === '.css') {

0 commit comments

Comments
 (0)