Coder Social home page Coder Social logo

red-meadow / meteor-vite Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jorgenvatle/meteor-vite

0.0 0.0 0.0 912 KB

⚡ Replace Meteor's bundler with Vite for blazing fast build-times

License: MIT License

JavaScript 54.66% TypeScript 42.24% HTML 3.09%

meteor-vite's Introduction

meteor-vite

Use Vite in your Meteor app! ⚡️

Roadmap

  • Development mode
  • Build
  • Importing non-core Meteor packages
  • Lazy meteor packages
  • Reify support
    • Named exports
    • Default exports
    • Re-exports (named + wildcard)
    • Re-exports via intermediary variable
  • Code-splitting/Dynamic imports
  • SSR (not tested)
  • Starter/demo templates

Installation

meteor add jorgenvatle:vite-bundler && meteor npm i -D vite meteor-vite

You can also install any vite plugin, for example @vitejs/plugin-vue:

meteor npm i -D @vitejs/plugin-vue

Make sure to have an import client entry (meteor.mainModule.client) in your package.json:

{
  "name": "my-app",
  "private": true,
  "scripts": {
    "dev": "meteor run",
    "build": "meteor build ../output/vue --directory"
  },
  "dependencies": {
    "@babel/runtime": "^7.17.9",
    "meteor-node-stubs": "^1.2.1",
    "vue": "^3.2.37"
  },
  "devDependencies": {
    "@types/meteor": "^1.4.87",
    "@vitejs/plugin-vue": "^3.0.3",
    "typescript": "^4.6.3",
    "vite": "^3.0.9"
  },
  "meteor": {
    "mainModule": {
      "client": "client/main.ts",
      "server": "server/main.ts"
    },
    "testModule": "tests/main.js"
  }
}

You can leave your Meteor client entry file empty, but it's necessary to enable Meteor import mode. In the example above, we can create an empty client/main.ts file.

Create a Vite configuration file (vite.config.js) in your project root:

import { defineConfig } from 'vite'
// Example with Vue
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [
    vue(),
  ],
  // Other vite options here...
})

As we don't use a standard Vite index.html file, we need to specify an entry point (different from the Meteor one):

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [
    vue(),
  ],

  meteor: {
    clientEntry: 'imports/ui/main.ts',
  },
})

You can then write your code from this entry point and it will be handled by Vite! ⚡️

Features

Lazy Loaded Meteor Packages

Meteor-Vite will automatically detect lazy loaded Meteor packages and import them into your Meteor client's entrypoint. This is necessary to ensure that the Vite bundler has access to your Meteor packages.

The imported files can safely be committed to your project repository. If you remove the associated package in the future, simply remove the import statement.

Our detection for these packages is fairly primitive, so it's best to keep the imports in the Meteor client entrypoint as specified in the meteor.mainModule.client field of your package.json file.

{
  "meteor": {
    "mainModule": {
      "client": "client/main.ts", // Lazy loaded packages are checked for and added here.
      "server": "server/main.ts"
    }
  }
}

Stub validation

Runtime validation at the client is performed for Meteor packages that are compiled by Vite. This is done to avoid a situation where Meteor-Vite incorrectly exports undefined values from a Meteor Package. Which can lead to silently broken Meteor packages.

The validation is done simply through verifying that package exports do not have a typeof value of undefined. If you do have a package that intentionally has undefined exports, you can disable the warning message for this package by excluding it in your Meteor settings.json file;

// vite.config.ts

import type { MeteorViteConfig } from 'meteor-vite';
export default defineConfig({
  // ...
  
  meteor: {
    clientEntry: 'imports/ui/main.ts',
    stubValidation: {
      /**
       * list of packages to ignore export validation for.
       */
      ignorePackages: ["ostrio:cookies"],

      /**
       * Will only emit warnings in the console instead of throwing an exception that may prevent the client app
       * from loading.
       */
      warnOnly: true,

      /**
       * Set to true to completely disable stub validation. Any of the above options will be ignored.
       * This is discuraged as `warnOnly` should give you an important heads up if something might be wrong with Meteor-Vite
       */
      disabled: false,
    }
  } satisfies MeteorViteConfig['meteor'],
})

meteor-vite's People

Contributors

jorgenvatle avatar akryum avatar github-actions[bot] avatar fredmaiaarantes avatar grubba27 avatar dependabot[bot] avatar red-meadow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.