GithubHelp home page GithubHelp logo

kevinzwhuang / json5-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webpack-contrib/json5-loader

0.0 1.0 0.0 11 KB

json5 loader module for webpack

License: MIT License

JavaScript 100.00%

json5-loader's Introduction

npm deps test coverage chat

JSON5 Loader

Webpack loader for parsing json5 files into JavaScript objects.

Install

$ npm install --save-dev json5-loader

Usage

You can use the loader either

  • by configuring the json5-loader in the module.loaders object of the webpack configuration, or
  • by directly using the json5! prefix to the require statement.

Suppose we have the following json5 file

// appData.json5
{
  env: 'production',
  passwordStregth: 'strong'
}

Usage with preconfigured loader

// webpack.config.js
module.exports = {
  entry: './index.js',
  output: { /* ... */ },
  module: {
    loaders: [
      {
        // make all files ending in .json5 use the `json5-loader`
        test: /\.json5$/,
        loader: 'json5-loader'
      }
    ]
  }
}
// index.js
var appConfig = require('./appData.json5')
// or, in ES6
// import appConfig from './appData.json5'

console.log(appConfig.env) // 'production'

Usage with require statement loader prefix

var appConfig = require("json5-loader!./appData.json5")
// returns the content as json parsed object

console.log(appConfig.env) // 'production'

Don't forget to polyfill require if you want to use it in Node.js. See the webpack documentation.

Maintainers


Tobias Koppers

PatrickJS

Michael Ferris

Keith McKnight

Radu Brehar

Kent C. Dodds

Steve Lacy

LICENSE

json5-loader's People

Contributors

patrickjs avatar stephenlacy avatar sokra avatar radubrehar avatar kmck avatar kevinzwhuang avatar cellule avatar

Watchers

James Cloos 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.