JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7741
  • Score
    100M100P100Q130766F
  • License MIT

Plugin for allowing .json5 and .jsonc files to be loaded.

Package Exports

  • vite-plugin-json5

Readme

🔌 Vite JSON5 (and JSONC) plugin

Plugin for allowing .json5 and .jsonc files to be loaded.

NOTE: This plugin is merely just a wrapper using the json5 package. So all the credits for t he parsing goes out to the collaborators of that repository.

📦 Installation in 3 easy steps:

1. Install the package into to your project

# PNPM:
pnpm i -D vite-plugin-json5

# Yarn:
yarn add -D vite-plugin-json5

# NPM:
npm install -D vite-plugin-json5

2. Add it to your vite config

// file: vite.config.js

import json5Plugin from 'vite-plugin-json5'

export default defineConfig({
  json5Plugin()
})

3. That's it 🎉

You are now able to import files with the .jsonc and .json5 extensions! These will be parsed by the json5 package and turned into a regular js that the app will be able to read and not get confused by.

🍕 Extra

The reason why I created the plugin is because I would like to be able to write comments in my JSON lang files to give more context about the translations. The problem was, when I imported a .json5 or .jsonc file it threw errors about needing a custom plugin for these types of files. I couldn't find one yet so... here it is! You should check the source code, it's laughable. Makes you think why Vite doesn't support it natively.