无痛创建复杂的 VSCode snippets 扩展的项目模板

2018-05-14 17:21:23 +08:00
 banxi1988

无痛创建复杂的 VSCode snippets 扩展的项目模板, 了解一下。 https://github.com/banxi1988/vscode-snippets-ext-template

核心要点: 原来很多 代码片段的内容段是直接在 snippets.json 文件中编写的。 这导致当代码片段中的内容比较复杂时,处理转义和缩进就比较麻烦了。比如:

"Vue Single File Component": {
		"prefix": "vbase",
		"body": [
			"<template>",
			"\t<div>",
			"",
			"\t</div>",
			"</template>",
			"",
			"<script>",
			"\texport default {",
			"\t\t${0}",
			"\t}",
			"</script>",
			"",
			"<style scoped>",
			"",
			"</style>"
		],
		"description": "Base for Vue File"
	}

正确的做法是将其中的 body 内容提取到一个单独的文件中。然后再合并生成最终的代码片段配置。

在我的项目中,创建了一个 NodeJS 脚本用来处理这其中的合并。 简化之后配置可以这样写了。

"vbase": {
 "description": "Vue Single File Component,Base for Vue File"
}

详细说明见 : https://github.com/banxi1988/vscode-snippets-ext-template 中的示例代码。

一个已经采用以上项目做法的 VSCode 代码片段扩展项目见:

https://github.com/wleven/wepy-snippets

了解一下。

3461 次点击
所在节点    Visual Studio Code
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/454773

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX