Skip to content

Commit

Permalink
fix(transformer-applet): ignore string when vue file is compiled
Browse files Browse the repository at this point in the history
  • Loading branch information
zguolee committed Oct 12, 2022
1 parent dcd240e commit 15d7301
Show file tree
Hide file tree
Showing 12 changed files with 758 additions and 837 deletions.
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -24,20 +24,20 @@
},
"devDependencies": {
"@antfu/eslint-config": "^0.27.0",
"@types/node": "^18.7.23",
"@types/node": "^18.8.4",
"@unocss-applet/preset-applet": "workspace:*",
"@unocss-applet/preset-rem-to-rpx": "workspace:*",
"@unocss-applet/transformer-applet": "workspace:*",
"@unocss-applet/transformer-attributify": "workspace:*",
"bumpp": "^8.2.1",
"eslint": "^8.24.0",
"eslint": "^8.25.0",
"esno": "^0.16.3",
"rimraf": "^3.0.2",
"typescript": "^4.8.4",
"unbuild": "^0.8.11",
"unocss": "^0.45.26",
"unocss": "^0.45.29",
"unocss-applet": "workspace:*",
"vite": "^3.1.0",
"vitest": "^0.23.4"
"vite": "^3.1.7",
"vitest": "^0.24.1"
}
}
6 changes: 3 additions & 3 deletions packages/preset-applet/package.json
Expand Up @@ -54,8 +54,8 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.26",
"@unocss/preset-mini": "^0.45.26",
"@unocss/preset-wind": "^0.45.26"
"@unocss/core": "^0.45.29",
"@unocss/preset-mini": "^0.45.29",
"@unocss/preset-wind": "^0.45.29"
}
}
2 changes: 1 addition & 1 deletion packages/preset-rem-to-rpx/package.json
Expand Up @@ -37,6 +37,6 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.26"
"@unocss/core": "^0.45.29"
}
}
4 changes: 2 additions & 2 deletions packages/transformer-applet/package.json
Expand Up @@ -35,9 +35,9 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.26"
"@unocss/core": "^0.45.29"
},
"devDependencies": {
"magic-string": "^0.26.4"
"magic-string": "^0.26.7"
}
}
15 changes: 9 additions & 6 deletions packages/transformer-applet/src/index.ts
Expand Up @@ -16,7 +16,7 @@ export default function transformerApplet(options: TransformerAppletOptions = {}
return {
name: 'transformer-applet',
enforce: 'pre',
async transform(s, _, ctx) {
async transform(s, id, ctx) {
let code = new MagicString(s.toString())

// process class attribute
Expand Down Expand Up @@ -60,13 +60,16 @@ export default function transformerApplet(options: TransformerAppletOptions = {}
let content = match[1]

if (content.startsWith(ignorePrefix)) {
content = content.substring(ignorePrefix.length).trim()
code.overwrite(start, start + match[0].length, match[0].replace(match[1], content))
// UniApp will replace string with a variable, so we need to ignore it when vue file is compiled
if (!/\.vue$/.test(id)) {
content = content.substring(ignorePrefix.length).trim()
code.overwrite(start, start + match[0].length, match[0].replace(match[1], content))
}
}
else {
// There may be no need
// https://tailwindcss.com/docs/background-image#arbitrary-values
// skip all the image formats in HTML for bg-[url('...')]
// There may be no need
// https://tailwindcss.com/docs/background-image#arbitrary-values
// skip all the image formats in HTML for bg-[url('...')]
if (/\.(png|jpg|jpeg|gif|svg)/g.test(content))
continue
// skip http(s)://
Expand Down
4 changes: 2 additions & 2 deletions packages/transformer-attributify/package.json
Expand Up @@ -35,9 +35,9 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.26"
"@unocss/core": "^0.45.29"
},
"devDependencies": {
"magic-string": "^0.26.4"
"magic-string": "^0.26.7"
}
}
4 changes: 2 additions & 2 deletions playground/tarojs/package.json
Expand Up @@ -35,7 +35,7 @@
"ios >= 8"
],
"dependencies": {
"@babel/runtime": "^7.19.0",
"@babel/runtime": "^7.19.4",
"@tarojs/components": "3.5.6",
"@tarojs/helper": "3.5.6",
"@tarojs/plugin-framework-vue3": "3.5.6",
Expand All @@ -58,7 +58,7 @@
"@tarojs/cli": "3.5.6",
"@tarojs/webpack5-runner": "3.5.6",
"@types/webpack-env": "^1.18.0",
"@unocss/webpack": "^0.45.26",
"@unocss/webpack": "^0.45.29",
"@vue/babel-plugin-jsx": "^1.1.1",
"@vue/compiler-sfc": "^3.2.40",
"babel-preset-taro": "3.5.6",
Expand Down
32 changes: 16 additions & 16 deletions playground/uni-app/package.json
Expand Up @@ -32,28 +32,28 @@
"build:quickapp-webview-union": "uni build -p quickapp-webview-union"
},
"dependencies": {
"@dcloudio/uni-app": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-app-plus": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-components": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-h5": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-mp-alipay": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-mp-baidu": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-mp-lark": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-mp-qq": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-mp-toutiao": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-mp-weixin": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-quickapp-webview": "3.0.0-alpha-3060420220922004",
"@dcloudio/uni-app": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-app-plus": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-components": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-h5": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-alipay": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-baidu": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-lark": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-qq": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-toutiao": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-weixin": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-quickapp-webview": "3.0.0-alpha-3060420220922008",
"vue": "^3.2.40",
"vue-i18n": "^9.2.2"
},
"devDependencies": {
"@dcloudio/types": "^3.0.15",
"@dcloudio/uni-automator": "3.0.0-alpha-3060420220922006",
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3060420220922006",
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-3060420220922006",
"@dcloudio/uni-automator": "3.0.0-alpha-3060420220922008",
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3060420220922008",
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-3060420220922008",
"@iconify-json/carbon": "^1.1.8",
"postcss": "^8.4.16",
"postcss": "^8.4.17",
"sass": "^1.55.0"
}
}
34 changes: 0 additions & 34 deletions playground/uni-app/src/components/AButton/AButton.vue

This file was deleted.

2 changes: 1 addition & 1 deletion playground/uni-app/src/manifest.json
Expand Up @@ -42,7 +42,7 @@
},
"quickapp": {},
"mp-weixin": {
"appid": "",
"appid": "wx59f6a03a5fe180ac",
"setting": {
"urlCheck": false
},
Expand Down
5 changes: 0 additions & 5 deletions playground/uni-app/src/pages/index/index.vue
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { ref } from 'vue'
import AButton from '../../components/AButton/AButton.vue'
const bg = 'bg-[hsl(2.7,81.9%,69.6%)]'
const bgIgnore = 'applet-ignore: bg-[hsl(2.7,81.9%,69.6%)]'
const index = 1
Expand Down Expand Up @@ -43,10 +42,6 @@ const bool = ref<boolean>()
<div class="m-0.5 p-1 text-2xl" :class="bool ? '' : 'text-yellow-500 p-2.5'">
abckefghijklmnopqrstuvwxyz
</div>
<AButton>primary</AButton>
<AButton type="success">
success
</AButton>
</div>
</template>

0 comments on commit 15d7301

Please sign in to comment.