Frontend Development 13 min read

Improving Frontend Efficiency with VSCode Snippets, Plop Generators, json-server Mock APIs, and Low‑Code Practices

The article outlines practical front‑end efficiency techniques—including VSCode snippets, Plop generators, json‑server mock APIs, component‑based business models, and low‑code tools—to achieve UI consistency, reduce boilerplate, and accelerate development across multiple projects.

JD Retail Technology
JD Retail Technology
JD Retail Technology
Improving Frontend Efficiency with VSCode Snippets, Plop Generators, json-server Mock APIs, and Low‑Code Practices

In frontend projects, developers often spend a lot of time initializing boilerplate code and dealing with inconsistent code styles, which raises maintenance costs.

To achieve UI consistency and code reuse, the article proposes several practical methods that improve efficiency through automation and intelligence.

1. VSCode custom snippets – Define reusable code fragments for basic page or block scaffolding; extensions for Vue2/Vue3 are available in the VSCode marketplace.

Applicable scenarios: building basic pages or code blocks.

Install snippet extensions from the VSCode marketplace.

2. Plop plugin – Generate boilerplate files from Handlebars templates. Installation, plopfile.js configuration, and action types (add, addMany, modify, append) are described.

// eslint-disable-next-line func-names
module.exports = function (plop) {
  plop.setGenerator('generator', {
    description: '创建列表模板',
    prompts: [{
      type: 'input',
      message: '请输入模块名称如system(可省略)',
      name: 'modeName',
      default: ''
    }, {
      type: 'input',
      name: 'apiName',
      message: '接口和存储的名称'
    }, {
      type: 'confirm',
      name: 'hasCreate',
      message: '是否需要创建页面',
      default: this.hasCreate
    }],
    actions: (data) => {
      const { hasCreate } = data;
      const actions = [{
        type: 'add',
        path: 'src/pages/{{modeName}}/list.vue',
        templateFile: 'plop-templates/list/list.hbs'
      }, {
        type: 'add',
        path: 'src/pages/{{modeName}}/components/config.js',
        templateFile: 'plop-templates/list/components/config.js'
      }, {
        type: 'add',
        path: 'src/pages/{{modeName}}/components/mixins.vue',
        templateFile: 'plop-templates/list/components/mixins.js'
      }, {
        type: 'modify',
        path: 'src/router/index.js',
        pattern: /\/\/ generator import/,
        template: "import {{modeName}} from './modules/{{modeName}}';\n// generator import"
      }, {
        type: 'modify',
        path: 'src/router/index.js',
        pattern: /\/\/ generator router/,
        template: `{
...{{modeName}},
},
// generator router`
      }, {
        type: 'add',
        path: 'src/router/modules/{{apiName}}.js',
        templateFile: 'plop-templates/list/route.js'
      }, {
        type: 'add',
        path: 'src/api/{{apiName}}.js',
        templateFile: 'plop-templates/api/demo.js'
      }, {
        type: 'add',
        path: 'src/store/modules/{{apiName}}/index.js',
        templateFile: 'plop-templates/store/index.js'
      }, {
        type: 'add',
        path: 'src/store/modules/{{apiName}}/db.json',
        templateFile: 'plop-templates/store/db.json'
      }];
      if (hasCreate) {
        actions.push({
          type: 'add',
          path: 'src/pages/{{modeName}}/create.vue',
          templateFile: 'plop-templates/list/create.vue'
        });
      }
      return actions;
    },
  });
};

Usage steps: install plop (npm install --save-dev plop), create a plopfile.js in the project root, add template files under plop-templates , and configure .gitignore to avoid committing generated files.

3. json-server – Quickly mock RESTful APIs from a simple db.json file. Installation and basic commands are shown, along with query parameters for filtering, pagination, and sorting.

{
  "posts": [{ "id": 1, "title": "json-server", "author": "swj8" }],
  "comments": [{ "id": 1, "body": "some comment", "postId": 1 }],
  "profile": { "name": "typicode" }
}

Typical endpoints: GET /posts – retrieve all data GET /posts?id_gte=1&id_lte=12 – range filter GET /posts?id_like=3 – fuzzy match GET /posts?_page=2&_limit=3 – pagination GET /posts?_sort=id&_order=desc – sorting POST, PUT, DELETE /posts – create, update, delete

4. Component‑based business model – Encapsulate common page logic (search, table, CRUD) into reusable configurations. Developers only need to define field definitions and API endpoints; the rest is generated automatically. This model has been applied in several internal platforms, reducing redundant code.

5–7. Additional tools – Combine the above methods to generate a full page in about 10 seconds, adopt low‑code design patterns for zero‑code page building, and use the JoyCode plugin for AI‑assisted code completion, image‑to‑code conversion, and code review.

Overall, the article presents a toolbox for front‑end teams to standardize UI, reduce repetitive coding, and accelerate delivery through snippets, Plop generators, mock APIs, component‑based models, and low‑code techniques.

frontendautomationlow-codecode snippetsjson-serverPlop
JD Retail Technology
Written by

JD Retail Technology

Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.