Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 728197e

Browse files
authored
fix: Make sure webpack is running properly (#68)
* chore: temp commit * fix: Make sure webpack is running properly
1 parent ee338ed commit 728197e

File tree

20 files changed

+3874
-229
lines changed

20 files changed

+3874
-229
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"dev": "pnpm run --filter @unplugin-vue-ce/build dev",
5151
"dev:v-model": "pnpm run --filter @unplugin-vue-ce/play-v-model dev",
5252
"dev:sub-style": "pnpm run --filter @unplugin-vue-ce/play-sub-style dev",
53+
"dev:sub-style-webpack": "pnpm run --filter @unplugin-vue-ce/play-sub-style-webpack serve",
5354
"dev:ce-app": "pnpm run --filter @unplugin-vue-ce/play-ce-app dev",
5455
"build": "pnpm run --filter @unplugin-vue-ce/build build",
5556
"release": "bumpp package.json packages/*/package.json utils/package.json --commit --push --tag",

packages/core/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { unVueCEVModel } from '@unplugin-vue-ce/v-model'
22
import { unVueCESubStyle } from '@unplugin-vue-ce/sub-style'
3-
import { unVueCEShadow } from '@unplugin-vue-ce/switch-shadow'
43
import { createUnplugin } from 'unplugin'
54
const unplugin = createUnplugin(() => {
65
return [
76
unVueCEVModel(),
8-
unVueCESubStyle(),
9-
unVueCEShadow(),
7+
...unVueCESubStyle(),
8+
// unVueCEShadow(),
109
]
1110
})
1211
export const viteVueCE = unplugin.vite

packages/sub-style/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ so you need to add the root component of each web component to add the reference
117117
@tailwind utilities;
118118
</style>
119119
```
120-
or
120+
or (only vite)
121121
```html
122122
<!-- xxx.vue -->
123123
<script>
@@ -137,7 +137,7 @@ you need to add the root component of each web component to add the reference st
137137
@unocss;
138138
</style>
139139
```
140-
or
140+
or (only vite)
141141
```html
142142
<!-- xxx.vue -->
143143
<script>
@@ -147,4 +147,4 @@ or
147147

148148
## About Windi CSS
149149
Windi css is not supported
150-
[Windi CSS is Sunsetting](https://windicss.org/posts/sunsetting.html)
150+
[Windi CSS is Sunsetting](https://windicss.org/posts/sunsetting.html)

packages/sub-style/index.ts

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,73 @@
11
import { createUnplugin } from 'unplugin'
2-
import { setGlobalPrefix } from 'baiwusanyu-utils'
2+
import { normalizePath, setGlobalPrefix } from 'baiwusanyu-utils'
33
import MagicString from 'magic-string'
44
import { NAME } from '@unplugin-vue-ce/utils'
55
import { injectVueRuntime } from './src/inject/inject-vue-runtime'
66
import { atomicCSSPreset, virtualTailwind, virtualUno } from './src/atomic-css'
77

88
export const unVueCESubStyle = (): any => {
99
setGlobalPrefix(`[${NAME}]:`)
10+
// just vite
1011
return [
1112
{
1213
name: `${NAME}:sub-style:pre`,
1314
enforce: 'pre',
14-
resolveId(id: string) {
15-
if (atomicCSSPreset[id as keyof typeof atomicCSSPreset])
16-
return `\0${id}`
15+
transformInclude(id: string) {
16+
return !id.endsWith('.html')
1717
},
18-
load(id: string) {
19-
if (id === `\0${virtualTailwind}` || id === `\0${virtualUno}`) {
20-
return {
21-
code: '',
18+
vite: {
19+
resolveId(id: string) {
20+
if (atomicCSSPreset[id as keyof typeof atomicCSSPreset])
21+
return `\0${id}`
22+
},
23+
load(id: string) {
24+
if (id === `\0${virtualTailwind}` || id === `\0${virtualUno}`) {
25+
return {
26+
code: '',
27+
}
2228
}
23-
}
24-
},
25-
transformInclude() {
26-
return true
27-
},
28-
async transform(code: string, id: string) {
29-
const mgcStr = new MagicString(code)
30-
if (id.endsWith('.vue') && code.includes(virtualTailwind))
31-
mgcStr.prependRight(mgcStr.length(), atomicCSSPreset[virtualTailwind])
29+
},
30+
transform(code: string, id: string) {
31+
const mgcStr = new MagicString(code)
32+
if (id.endsWith('.vue') && code.includes(virtualTailwind))
33+
mgcStr.prependRight(mgcStr.length(), atomicCSSPreset[virtualTailwind])
3234

33-
if (id.endsWith('.vue') && code.includes(virtualUno))
34-
mgcStr.prependRight(mgcStr.length(), atomicCSSPreset[virtualUno])
35+
if (id.endsWith('.vue') && code.includes(virtualUno))
36+
mgcStr.prependRight(mgcStr.length(), atomicCSSPreset[virtualUno])
3537

36-
return {
37-
code: mgcStr.toString(),
38-
get map() {
39-
return mgcStr.generateMap({
40-
source: id,
41-
includeContent: true,
42-
hires: true,
43-
})
44-
},
45-
}
38+
return {
39+
code: mgcStr.toString(),
40+
get map() {
41+
return mgcStr.generateMap({
42+
source: id,
43+
includeContent: true,
44+
hires: true,
45+
})
46+
},
47+
}
48+
},
4649
},
4750
},
4851
{
4952
name: `${NAME}:sub-style:post`,
5053
enforce: 'post',
51-
transformInclude() {
52-
return true
54+
transformInclude(id: string) {
55+
return !id.endsWith('.html')
5356
},
5457
async transform(code: string, id: string) {
58+
const formatId = normalizePath(id)
5559
const mgcStr = new MagicString(code)
56-
57-
// build only
58-
if (id.includes('@vue/runtime-dom/dist/runtime-dom.esm-bundler.js'))
60+
// build only / webpack dev
61+
if (formatId.includes('@vue/runtime-dom/dist/runtime-dom.esm-bundler.js'))
5962
injectVueRuntime(mgcStr)
6063

61-
// build only
62-
if (id.includes('@vue/runtime-core/dist/runtime-core.esm-bundler.js'))
64+
// build only / webpack dev
65+
if (formatId.includes('@vue/runtime-core/dist/runtime-core.esm-bundler.js'))
6366
injectVueRuntime(mgcStr)
6467

65-
// dev only
66-
if (id.includes('.vite/deps/vue.js')
67-
|| (id.includes('.vite/deps/chunk') && code.includes('__isVue')))
68+
// vite dev only
69+
if (formatId.includes('.vite/deps/vue.js')
70+
|| (formatId.includes('.vite/deps/chunk') && code.includes('__isVue')))
6871
injectVueRuntime(mgcStr)
6972

7073
return {

packages/switch-shadow/index.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createUnplugin } from 'unplugin'
2-
import { setGlobalPrefix } from 'baiwusanyu-utils'
2+
import { normalizePath, setGlobalPrefix } from 'baiwusanyu-utils'
33
import MagicString from 'magic-string'
44
import { NAME } from '@unplugin-vue-ce/utils'
55

@@ -8,28 +8,29 @@ export const unVueCEShadow = (): any => {
88
return {
99
name: `${NAME}:switch-shadow`,
1010
enforce: 'post',
11-
transformInclude() {
12-
return true
11+
transformInclude(id: string) {
12+
return !id.endsWith('.html')
1313
},
1414
async transform(code: string, id: string) {
15+
const formatId = normalizePath(id)
1516
const mgcStr = new MagicString(code)
1617

17-
// build only
18-
if (id.includes('@vue/runtime-dom/dist/runtime-dom.esm-bundler.js'))
19-
console.log(id)
18+
// build only / webpack dev
19+
if (formatId.includes('@vue/runtime-dom/dist/runtime-dom.esm-bundler.js'))
20+
console.log(formatId)
2021

2122
// injectVueRuntime(mgcStr)
2223

23-
// build only
24-
if (id.includes('@vue/runtime-core/dist/runtime-core.esm-bundler.js'))
25-
console.log(id)
24+
// build only / webpack dev
25+
if (formatId.includes('@vue/runtime-core/dist/runtime-core.esm-bundler.js'))
26+
console.log(formatId)
2627

2728
// injectVueRuntime(mgcStr)
2829

29-
// dev only
30-
if (id.includes('.vite/deps/vue.js')
31-
|| (id.includes('.vite/deps/chunk') && code.includes('__isVue')))
32-
console.log(id)
30+
// vite dev only
31+
if (formatId.includes('.vite/deps/vue.js')
32+
|| (formatId.includes('.vite/deps/chunk') && code.includes('__isVue')))
33+
console.log(formatId)
3334

3435
// injectVueRuntime(mgcStr)
3536
return {

packages/v-model/index.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createUnplugin } from 'unplugin'
2-
import { setGlobalPrefix } from 'baiwusanyu-utils'
2+
import { normalizePath, setGlobalPrefix } from 'baiwusanyu-utils'
33
import MagicString from 'magic-string'
44
import { NAME } from '@unplugin-vue-ce/utils'
55
import { injectVueRuntime } from './src/inject-vue-runtime'
@@ -11,28 +11,29 @@ export const unVueCEVModel = (): any => {
1111
return {
1212
name: `${NAME}:v-model`,
1313
enforce: 'post',
14-
transformInclude() {
15-
return true
14+
transformInclude(id: string) {
15+
return !id.endsWith('.html')
1616
},
1717
async transform(code: string, id: string) {
1818
const mgcStr = new MagicString(code)
19-
// build only
20-
if (id.includes('/@vue/shared/dist/shared.esm-bundler.js'))
19+
const formatId = normalizePath(id)
20+
// build only / webpack dev
21+
if (formatId.includes('/@vue/shared/dist/shared.esm-bundler.js'))
2122
injectIsCEModifiers(mgcStr, false)
2223

23-
// build only
24-
if (id.includes('@vue/runtime-dom/dist/runtime-dom.esm-bundler.js')) {
24+
// build only / webpack dev
25+
if (formatId.includes('@vue/runtime-dom/dist/runtime-dom.esm-bundler.js')) {
2526
injectVueRuntime(mgcStr)
2627
injectImport(mgcStr)
2728
}
2829

29-
// build only
30-
if (id.includes('@vue/runtime-core/dist/runtime-core.esm-bundler.js'))
30+
// build only / webpack dev
31+
if (formatId.includes('@vue/runtime-core/dist/runtime-core.esm-bundler.js'))
3132
injectEmit(mgcStr)
3233

33-
// dev only
34-
if (id.includes('.vite/deps/vue.js')
35-
|| (id.includes('.vite/deps/chunk') && code.includes('__isVue'))) {
34+
// vite dev only
35+
if (formatId.includes('.vite/deps/vue.js')
36+
|| (formatId.includes('.vite/deps/chunk') && code.includes('__isVue'))) {
3637
injectVueRuntime(mgcStr)
3738
injectIsCEModifiers(mgcStr, true)
3839
}

play/sub-style-webpack/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.DS_Store
2+
holy/node_modules
3+
/dist
4+
5+
6+
# local env files
7+
.env.local
8+
.env.*.local
9+
10+
# Log files
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
pnpm-debug.log*
15+
16+
# Editor directories and files
17+
.idea
18+
.vscode
19+
*.suo
20+
*.ntvs*
21+
*.njsproj
22+
*.sln
23+
*.sw?

play/sub-style-webpack/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoist=true

play/sub-style-webpack/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# holy
2+
3+
## Project setup
4+
```
5+
pnpm install
6+
```
7+
8+
### Compiles and hot-reloads for development
9+
```
10+
pnpm run serve
11+
```
12+
13+
### Compiles and minifies for production
14+
```
15+
pnpm run build
16+
```
17+
18+
### Customize configuration
19+
See [Configuration Reference](https://cli.vuejs.org/config/).

play/sub-style-webpack/package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@unplugin-vue-ce/play-sub-style-webpack",
3+
"private": true,
4+
"version": "0.1.0",
5+
"scripts": {
6+
"serve": "vue-cli-service serve",
7+
"build": "vue-cli-service build",
8+
"preview": "cd dist && npx http-server -p 8081"
9+
},
10+
"dependencies": {
11+
"@unocss/postcss": "^0.55.2",
12+
"postcss": "^8.4.28",
13+
"unocss": "^0.55.2",
14+
"vue": "^3.2.13"
15+
},
16+
"devDependencies": {
17+
"@unocss/webpack": "latest",
18+
"@vue/cli-plugin-typescript": "~5.0.0",
19+
"@vue/cli-service": "~5.0.0",
20+
"baiwusanyu-utils": "^1.0.15",
21+
"typescript": "~4.5.5",
22+
"unplugin": "^1.4.0"
23+
},
24+
"browserslist": [
25+
"> 1%",
26+
"last 2 versions",
27+
"not dead",
28+
"not ie 11"
29+
]
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
plugins: {
3+
'@unocss/postcss': {},
4+
},
5+
}

play/sub-style-webpack/src/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<bwsy-ce-foo />
3+
</template>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
<p class="bar">
4+
should be blue -- bar
5+
</p>
6+
</div>
7+
</template>
8+
9+
<style scoped>
10+
.bar {
11+
color: blue;
12+
}
13+
</style>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<div>
3+
<p class="foo bg-blue">
4+
should be red -- foo
5+
</p>
6+
<BwsyBar />
7+
</div>
8+
</template>
9+
10+
<script setup>
11+
import BwsyBar from './bwsy-bar.vue'
12+
// import '@virtual:uno'
13+
</script>
14+
15+
<style scoped>
16+
.foo {
17+
color: red;
18+
}
19+
@unocss preflights;
20+
@unocss default;
21+
@unocss;
22+
</style>

play/sub-style-webpack/src/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createApp, defineCustomElement } from 'vue'
2+
import 'uno.css'
3+
import App from './App.vue'
4+
import Foo from './bwsy-ce-foo.ce.vue'
5+
const app = createApp(App)
6+
customElements.define('bwsy-ce-foo', defineCustomElement(Foo))
7+
app.mount('#app')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '*.vue' {
2+
import type { DefineComponent } from 'vue'
3+
const component: DefineComponent<{}, {}, any>
4+
export default component
5+
}

0 commit comments

Comments
 (0)