A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://frederikbache.github.io/vue-vroom/guide/intro/organization.html below:

Website Navigation


Organisation and optimization | Vue goes Vroom

Organisation and optimization #

Even small projects can quickly get many models, seeds and custom routes. Here's a few ideas for organizing your code to keep it easy to read and to make sure that development code like seeds, filters and routes are not bundled into your production build.

An example dir structure #

A way to structure you vroom dir could be

An example with seeds #

Setup models (could be split in even more files)

typescript
// vroom/models/index.ts
import { defineModels } from "vue-vroom";
import models from "./models";

export default {
  todo: defineModel({
    schema: {
      title: { type: String },
      completed: { type: Boolean },
    },
  }),
};

Load the models and create the Vroom instance

typescript
// vroom/setup.ts
import { createVroom } from 'vue-vroom'
import models from './models'

const vroom = createVroom({
    models,
    server: {
        enable: true,
    }
})

export vroom;

Use the vroom instance in the seed function to add mock data

typescript
// vroom/seeds/index.ts
import vroom from "../setup";

export default function seed() {
  const { db } = vroom;

  db.todo.create({
    title: "Buy milk",
    completed: false,
  });
}

Only call the seed function in non production environments (should allow your bundler to keep the seed function out of your bundle)

typescript
// vroom/index.ts
import vroom from "./setup";
import seed from "./seed";

if (process.env.NODE_ENV !== "production") {
  seed();
}

export default vroom;

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4