-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin-vue): make cssm code tree shakeable (#6353)
- Loading branch information
Showing
12 changed files
with
143 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// @ts-check | ||
// this is automtically detected by scripts/jestPerTestSetup.ts and will replace | ||
// the default e2e test serve behavior | ||
|
||
exports.serve = async function serve() { | ||
// do nothing, skip default behavior | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { build } from 'vite' | ||
import path from 'path' | ||
import type { OutputChunk, RollupOutput } from 'rollup' | ||
|
||
describe('vue component library', () => { | ||
test('should output tree shakeable css module code', async () => { | ||
// Build lib | ||
await build({ | ||
logLevel: 'silent', | ||
configFile: path.resolve(__dirname, '../vite.config.lib.ts') | ||
}) | ||
// Build app | ||
const { output } = (await build({ | ||
logLevel: 'silent', | ||
configFile: path.resolve(__dirname, '../vite.config.consumer.ts') | ||
})) as RollupOutput | ||
const { code } = output.find( | ||
(e) => e.type === 'chunk' && e.isEntry | ||
) as OutputChunk | ||
// Unused css module should be treeshaked | ||
expect(code).toContain('styleA') // styleA is used by CompA | ||
expect(code).not.toContain('styleB') // styleB is not used | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./src-consumer/index.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "test-vue-lib", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev-consumer": "vite --config ./vite.config.consumer.ts", | ||
"build-lib": "vite build --config ./vite.config.lib.ts", | ||
"build-consumer": "vite build --config ./vite.config.consumer.ts" | ||
}, | ||
"dependencies": { | ||
"vue": "^3.2.25" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-vue": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @ts-ignore | ||
/* eslint-disable node/no-missing-import */ | ||
import { CompA } from '../dist/lib/my-vue-lib.es' | ||
import '../dist/lib/style.css' | ||
import { createApp } from 'vue' | ||
|
||
const app = createApp(CompA) | ||
app.mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<template> | ||
<div :class="$style.styleA">CompA</div> | ||
</template> | ||
<style module> | ||
.styleA { | ||
color: red; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<template> | ||
<div :class="$style.styleB">CompB</div> | ||
</template> | ||
<style module> | ||
.styleB { | ||
color: blue; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as CompA } from './CompA.vue' | ||
export { default as CompB } from './CompB.vue' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
root: __dirname, | ||
build: { | ||
outDir: 'dist/consumer' | ||
}, | ||
plugins: [vue()] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import path from 'path' | ||
import { defineConfig } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
root: __dirname, | ||
build: { | ||
outDir: 'dist/lib', | ||
lib: { | ||
entry: path.resolve(__dirname, 'src-lib/index.ts'), | ||
name: 'MyVueLib', | ||
formats: ['es'], | ||
fileName: (format) => `my-vue-lib.${format}.js` | ||
}, | ||
rollupOptions: { | ||
external: ['vue'], | ||
output: { | ||
globals: { vue: 'Vue' } | ||
} | ||
} | ||
}, | ||
plugins: [vue()] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.