json5-loader
json5 loader module for webpack
Last updated 14 days ago by evilebottnawi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install json5-loader 
SYNC missed versions from official npm registry.

npm node deps tests cover chat size

json5-loader

A webpack loader for parsing json5 files into JavaScript objects.

Getting Started

To begin, you'll need to install json5-loader:

$ npm install json5-loader --save-dev

You can use the loader either:

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

Suppose we have the following json5 file:

file.json5

{
  env: 'production',
  passwordStrength: 'strong',
}

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.json5$/i,
        loader: 'json5-loader',
        type: 'javascript/auto',
      },
    ],
  },
};

Options

Name Type Default Description
esModule {Boolean} true Uses ES modules syntax

esModule

Type: Boolean Default: true

There are some cases in which using ES modules is beneficial, like in the case of module concatenation and tree shaking.

You can enable a ES module syntax using:

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.json5$/i,
        loader: 'json5-loader',
        options: {
          esModule: false,
        },
        type: 'javascript/auto',
      },
    ],
  },
};

Examples

Usage with require statement loader prefix

file.json5

{
  env: 'production',
  passwordStrength: 'strong',
}

index.js

import appConfig from 'json5-loader!./file.json5';

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

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

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

Current Tags

  • 2.0.0-beta.0                                ...           beta (3 years ago)
  • 4.0.1                                ...           latest (14 days ago)

10 Versions

  • 4.0.1                                ...           14 days ago
  • 4.0.0                                ...           6 months ago
  • 3.0.0                                ...           a year ago
  • 2.0.0                                ...           2 years ago
  • 2.0.0-beta.0                                ...           3 years ago
  • 1.0.1                                ...           4 years ago
  • 0.6.0                                ...           6 years ago
  • 0.5.0                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago

Copyright 2014 - 2016 © taobao.org |