banxi1988

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

  •  
  •   banxi1988 ·
    banxi1988 · May 14, 2018 · 4113 views
    This topic created in 2927 days ago, the information mentioned may be changed or developed.

    无痛创建复杂的 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

    了解一下。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2951 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 14:35 · PVG 22:35 · LAX 07:35 · JFK 10:35
    ♥ Do have faith in what you're doing.