mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
fix(webpack): can't resolve absolute url in css (#8555)
This commit is contained in:
parent
ac762299a1
commit
b2e38f5c92
@ -104,6 +104,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"localIdentName\\": \\"[local]_[hash:base64:5]\\",
|
||||
},
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -135,6 +136,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"esModule\\": false,
|
||||
\\"importLoaders\\": 2,
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -175,6 +177,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"localIdentName\\": \\"[local]_[hash:base64:5]\\",
|
||||
},
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -206,6 +209,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"esModule\\": false,
|
||||
\\"importLoaders\\": 2,
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -246,6 +250,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"localIdentName\\": \\"[local]_[hash:base64:5]\\",
|
||||
},
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -283,6 +288,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"esModule\\": false,
|
||||
\\"importLoaders\\": 2,
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -329,6 +335,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"localIdentName\\": \\"[local]_[hash:base64:5]\\",
|
||||
},
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -369,6 +376,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"esModule\\": false,
|
||||
\\"importLoaders\\": 2,
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -418,6 +426,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"localIdentName\\": \\"[local]_[hash:base64:5]\\",
|
||||
},
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -455,6 +464,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"esModule\\": false,
|
||||
\\"importLoaders\\": 2,
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -501,6 +511,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"localIdentName\\": \\"[local]_[hash:base64:5]\\",
|
||||
},
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
@ -538,6 +549,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
|
||||
\\"esModule\\": false,
|
||||
\\"importLoaders\\": 2,
|
||||
\\"sourceMap\\": false,
|
||||
\\"url\\": [Function isUrlResolvingEnabled],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import path from 'path'
|
||||
import consola from 'consola'
|
||||
import ExtractCssChunksPlugin from 'extract-css-chunks-webpack-plugin'
|
||||
|
||||
import { wrapArray } from '@nuxt/utils'
|
||||
@ -25,6 +26,16 @@ export default class StyleLoader {
|
||||
return Boolean(this.isServer && this.extractCSS)
|
||||
}
|
||||
|
||||
isUrlResolvingEnabled (url, resourcePath) {
|
||||
// Ignore absolute URLs, it will be handled by serve-static.
|
||||
if (url.startsWith('/')) {
|
||||
consola.warn(`Please use relative path or alias path instead of absolute path ${url}`)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
normalize (loaders) {
|
||||
loaders = wrapArray(loaders)
|
||||
return loaders.map(loader => (typeof loader === 'string' ? { loader } : loader))
|
||||
@ -71,6 +82,10 @@ export default class StyleLoader {
|
||||
css (options) {
|
||||
const cssLoader = { loader: this.resolveModule('css-loader'), options }
|
||||
|
||||
if (!options.url) {
|
||||
options.url = this.isUrlResolvingEnabled
|
||||
}
|
||||
|
||||
if (this.exportOnlyLocals) {
|
||||
options.modules = {
|
||||
...options.modules,
|
||||
|
Loading…
Reference in New Issue
Block a user