Skip to content

A Vite plugin that enables you to import JSONC and JSON5 files as modules in your Vite project

License

Notifications You must be signed in to change notification settings

gokhantaskan/vite-plugin-jsonx

Repository files navigation

vite-plugin-jsonx

This is a Vite plugin that enables you to import JSONC and JSON5 files as modules in your Vite project.

Features

  • Import JSON5 files as modules
  • Import JSONC files as modules
  • Customizable parse options for both JSON5 and JSONC files

Installation

You can install the plugin using npm:

npm install vite-plugin-jsonx --save-dev

Or you can use yarn:

yarn add vite-plugin-jsonx --dev

Usage

To use this plugin, first add it to your vite.config.js or vite.config.ts:

import { jsonX } from 'vite-plugin-jsonx';

export default {
  plugins: [
    jsonX()
  ]
}

or with custom options:

export default {
  plugins: [
    jsonX({
      json5ParserOptions // optional, custom parser options for json5
      jsoncParserOptions // optional, custom parser options for jsonc
    })
  ]
}

Add the following to your env.d.ts file:

/// <reference types="vite-plugin-jsonx/client" />

With this setup, you can now import JSONC and JSON5 files in your application:

import datac from './data.jsonc';
import data5 from './data.json5';

Options

This plugin supports the following options:

  • jsoncParserOptions: An optional object with custom parsing options for JSONC files. For more information, visit the documentation.
  • json5ParserOptions: An optional object with custom parsing options for JSON5 files. For more information, visit the documentation.

About

A Vite plugin that enables you to import JSONC and JSON5 files as modules in your Vite project

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published