mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
feat(wepack): support @import
using ~assets
in css files (#6987)
This commit is contained in:
parent
6d79206a68
commit
10ac6aed9a
@ -45,15 +45,31 @@ export default class PostcssConfig {
|
||||
return this.buildContext.buildOptions.postcss
|
||||
}
|
||||
|
||||
get postcssImportAlias () {
|
||||
const alias = { ...this.buildContext.options.alias }
|
||||
|
||||
for (const key in alias) {
|
||||
if (key.startsWith('~')) {
|
||||
continue
|
||||
}
|
||||
const newKey = '~' + key
|
||||
if (!alias[newKey]) {
|
||||
alias[newKey] = alias[key]
|
||||
}
|
||||
}
|
||||
|
||||
return alias
|
||||
}
|
||||
|
||||
get defaultConfig () {
|
||||
const { dev, alias, srcDir, rootDir, modulesDir } = this.buildContext.options
|
||||
const { dev, srcDir, rootDir, modulesDir } = this.buildContext.options
|
||||
return {
|
||||
sourceMap: this.buildContext.buildOptions.cssSourceMap,
|
||||
plugins: {
|
||||
// https://github.com/postcss/postcss-import
|
||||
'postcss-import': {
|
||||
resolve: createResolver({
|
||||
alias: { ...alias },
|
||||
alias: this.postcssImportAlias,
|
||||
modules: [srcDir, rootDir, ...modulesDir]
|
||||
})
|
||||
},
|
||||
|
1
test/fixtures/basic/assets/app.css
vendored
Normal file
1
test/fixtures/basic/assets/app.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
@import "~assets/import.css";
|
1
test/fixtures/basic/assets/import.css
vendored
Normal file
1
test/fixtures/basic/assets/import.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.import-css { color: red; }
|
3
test/fixtures/basic/nuxt.config.js
vendored
3
test/fixtures/basic/nuxt.config.js
vendored
@ -74,6 +74,9 @@ export default {
|
||||
handler: (_, res) => res.end('Works!')
|
||||
}
|
||||
],
|
||||
css: [
|
||||
'~assets/app.css'
|
||||
],
|
||||
build: {
|
||||
scopeHoisting: true,
|
||||
publicPath: '',
|
||||
|
Loading…
Reference in New Issue
Block a user