feat(wepack): support @import using ~assets in css files (#6987)

This commit is contained in:
Xin Du (Clark) 2020-02-24 22:47:43 +00:00 committed by GitHub
parent 6d79206a68
commit 10ac6aed9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 2 deletions

View File

@ -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
View File

@ -0,0 +1 @@
@import "~assets/import.css";

1
test/fixtures/basic/assets/import.css vendored Normal file
View File

@ -0,0 +1 @@
.import-css { color: red; }

View File

@ -74,6 +74,9 @@ export default {
handler: (_, res) => res.end('Works!')
}
],
css: [
'~assets/app.css'
],
build: {
scopeHoisting: true,
publicPath: '',