Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(compiler-sfc): bump postcss to version 8 #2649

Closed
wants to merge 10 commits into from
7 changes: 4 additions & 3 deletions packages/compiler-sfc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-sfc#readme",
"peerDependencies": {
"vue": "3.0.2"
"vue": "3.0.2",
"postcss": "^8.1.8"
},
"dependencies": {
"@babel/parser": "^7.12.0",
Expand All @@ -46,7 +47,6 @@
"lru-cache": "^5.1.1",
"magic-string": "^0.25.7",
"merge-source-map": "^1.1.0",
"postcss": "^7.0.32",
"postcss-modules": "^3.2.2",
"postcss-selector-parser": "^6.0.4",
"source-map": "^0.6.1"
Expand All @@ -55,6 +55,7 @@
"@types/consolidate": "^0.14.0",
"@types/lru-cache": "^5.1.0",
"pug": "^2.0.4",
"sass": "^1.26.9"
"sass": "^1.26.9",
"postcss": "^8.1.8"
}
}
13 changes: 4 additions & 9 deletions packages/compiler-sfc/src/compileStyle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import postcss, {
ProcessOptions,
LazyResult,
Result,
ResultMap,
ResultMessage
} from 'postcss'
import postcss, { Message, ProcessOptions, Result, SourceMap } from 'postcss'
import trimPlugin from './stylePluginTrim'
import scopedPlugin from './stylePluginScoped'
import {
Expand All @@ -15,6 +9,7 @@ import {
} from './stylePreprocessors'
import { RawSourceMap } from 'source-map'
import { cssVarsPlugin } from './cssVars'
import LazyResult from 'postcss/lib/lazy-result'
lstoeferle marked this conversation as resolved.
Show resolved Hide resolved

export interface SFCStyleCompileOptions {
source: string
Expand Down Expand Up @@ -140,7 +135,7 @@ export function doCompileStyle(

let result: LazyResult | undefined
let code: string | undefined
let outMap: ResultMap | undefined
let outMap: SourceMap | undefined
// stylus output include plain css. so need remove the repeat item
const dependencies = new Set(
preProcessedSource ? preProcessedSource.dependencies : []
Expand All @@ -153,7 +148,7 @@ export function doCompileStyle(
errors.push(...preProcessedSource.errors)
}

const recordPlainCssDependencies = (messages: ResultMessage[]) => {
const recordPlainCssDependencies = (messages: Message[]) => {
messages.forEach(msg => {
if (msg.type === 'dependency') {
// postcss output path is absolute position path
Expand Down
11 changes: 6 additions & 5 deletions packages/compiler-sfc/src/cssVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { SFCDescriptor } from './parse'
import { rewriteDefault } from './rewriteDefault'
import { ParserPlugin } from '@babel/parser'
import postcss, { Root } from 'postcss'
import { Root } from 'postcss'
import hash from 'hash-sum'

export const CSS_VARS_HELPER = `useCssVars`
Expand Down Expand Up @@ -64,9 +64,9 @@ export interface CssVarsPluginOptions {
isProd: boolean
}

export const cssVarsPlugin = postcss.plugin<CssVarsPluginOptions>(
'vue-scoped',
opts => (root: Root) => {
export const cssVarsPlugin = (opts: CssVarsPluginOptions) => ({
postcssPlugin: 'vue-scoped',
Root(root: Root) {
const { id, isProd } = opts!
const shortId = id.replace(/^data-v-/, '')
root.walkDecls(decl => {
Expand All @@ -78,7 +78,8 @@ export const cssVarsPlugin = postcss.plugin<CssVarsPluginOptions>(
}
})
}
)
})
cssVarsPlugin.postcss = true

export function genCssVarsCode(
vars: string[],
Expand Down
Loading