diff --git a/package.json b/package.json index e1a781b20..1345a65b2 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^9.0.0", "@rollup/plugin-replace": "^2.2.1", + "@types/hash-sum": "^1.0.0", "@types/jest": "^26.0.0", "@types/node": "^14.10.1", "@types/puppeteer": "^2.0.0", diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts index d8a8d1a6b..cdd676989 100644 --- a/packages/compiler-sfc/__tests__/cssVars.spec.ts +++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts @@ -52,7 +52,7 @@ describe('CSS vars injection', () => { assertCode(content) }) - test('should rewrite CSS vars in scoped mode', () => { + test('should rewrite CSS vars in compileStyle', () => { const { code } = compileStyle({ source: `.foo { color: v-bind(color); @@ -69,6 +69,37 @@ describe('CSS vars injection', () => { `) }) + test('prod mode', () => { + const { content } = compileSFCScript( + `\n` + + ``, + { isProd: true } + ) + expect(content).toMatch(`_useCssVars(_ctx => ({ + "4003f1a6": (_ctx.color), + "41b6490a": (_ctx.font.size) +}))}`) + + const { code } = compileStyle({ + source: `.foo { + color: v-bind(color); + font-size: v-bind('font.size'); + }`, + filename: 'test.css', + id: mockId, + isProd: true + }) + expect(code).toMatchInlineSnapshot(` + ".foo { + color: var(--4003f1a6); + font-size: var(--41b6490a); + }" + `) + }) + describe('codegen', () => { test('