npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-wechat-wxs

v1.0.3

Published

在wxs(微信小程序脚本语言)里写模板字符串,以及用 let 和 const 声明变量

Downloads

17

Readme

gulp-wechat-wxs

gulp-wechat-wxs 是一个 gulp 插件。
如果你习惯了使用模板字符串,用let 和 const 声明变量。然而却被wxs的语法(微信小程序脚本语言)折磨着。 你要做的不是改变自己的习惯,而是在你的项目里用上此插件。

gulp-wechat-wxs 帮你将模板字符串和用let、const 声明的变量转换为wxs支持的语法。

使用

安装依赖

npm install gulp gulp-wechat-wxs -D

在你的 gulpfile 中这样写

const {src, dest } = require('gulp')
const GulpWechatWXS = require("gulp-wechat-wxs")

function defaultTask(cb) {
    return src(["./src/**.wxs","./src/**.wxml"])
        .pipe(GulpWechatWXS())
        .pipe(dest("./dist"))
}

exports.default = defaultTask

比较省事的用法

会直接替换掉源文件

const {src, dest } = require('gulp')
const GulpWechatWXS = require("gulp-wechat-wxs")

function defaultTask(cb) {
    return src(["**/**.wxs","**/**.wxml"])
        .pipe(GulpWechatWXS())
        .pipe(dest("./"))
}

exports.default = defaultTask

支持的写法

1. 支持 WXML 中嵌入的 wxs

源文件

<wxs module="ddd">
    function f() {
    let a = 123333
    return `answer is ${a+100} haha`
    }
</wxs>

<view>支持在wxml里嵌入的wxs代码</view>

<wxs module="ttt">
const a = `可以在\${}中进行一些支持的运算。`;
</wxs>

处理后的文件

<wxs module="ddd">
    function f() {
    var a = 123333
    return "answer is " + (a+100) + " haha"
    }
</wxs>

<view>支持在wxml里嵌入的wxs代码</view>

<wxs module="ttt">
var a = "可以在\${}中进行一些支持的运算。";
</wxs>

2. 支持 wxs 文件

源文件

function bar() {
    const a = `可以在\${}中进行一些支持的运算。${Math.PI * 2} is PI`;
    const b = `转义的字符也会被正确处理\`,Dont worry.`
    const c = `\${} 这个不会被误处理,${ 'c' + '\}'} 这个也不会被误处理`
    let f=1;let d=3;const v=4; // 不换行也可以检测到
    return `the result is ${a} ${b} ${c+f+d+v}`
}

module.exports = {
    foo: foo
}

处理后的文件

function bar() {
    var a = "可以在\${}中进行一些支持的运算。" + (Math.PI * 2) + " is PI";
    var b = "转义的字符也会被正确处理\`,Dont worry."
    var c = "\${} 这个不会被误处理," + ( 'c' + '\}') + " 这个也不会被误处理"
    var f=1;var d=3;var v=4; // 不换行也可以检测到
    return "the result is " + (a) + " " + (b) + " " + (c+f+d+v) + ""
}

module.exports = {
    foo: foo
}

暂不支持的用法

由于js中的正则表达式不支持平衡组,类似"${xxx}}} ${123}"这种的字符串,没法知道应该匹配到哪一个}才算完。

不能在 ${} 中 嵌套对象,比如

`${ {a:1} }`
`${JSON.stringify({a:1})}`
// 上面两种写法都是不支持的
// 但是支持转义,下面的写法都会被正确处理
`\${}`
`${'\}'}`