json5-loader
json5-loader
安装
$ npm install --save-dev json5-loader
用法
你可以通过以下用法使用这个加载器
- 在 webpack 配置里的 
module.loaders对象中配置json5-loader; - 直接在 require 语句中使用 
json5!前缀。 
假设我们有下面这个 json5 文件
// appData.json5
{
  env: 'production',
  passwordStregth: 'strong'
}
预先配置加载器的用法
// webpack.config.js
module.exports = {
  entry: './index.js',
  output: { /* ... */ },
  module: {
    loaders: [
      {
        // 使所有以 .json5 结尾的文件使用 `json5-loader`
        test: /\.json5$/,
        loader: 'json5-loader'
      }
    ]
  }
}
// index.js
var appConfig = require('./appData.json5')
// 或者 ES6 语法
// import appConfig from './appData.json5'
console.log(appConfig.env) // 'production'
require 语句使用加载器前缀的用法
var appConfig = require("json5-loader!./appData.json5")
// 返回的是解析好的对象
console.log(appConfig.env) // 'production'
如果需要在 Node.js 中使用,不要忘记兼容(polyfill)require。更多参考 webpack 文档。
维护者
| 
         Tobias Koppers  | 
      
         PatrickJS  | 
      
         Michael Ferris  | 
      
         Keith McKnight  | 
    
| 
         Radu Brehar  | 
      
         Kent C. Dodds  | 
      
         Steve Lacy  | 
    |
LICENSE
MIT