- 0133技术站
- 联系QQ:18840023
- QQ交流群

- 微信公众号

A webpack loader for parsing json5
files into JavaScript objects.
$ npm install --save-dev json5-loader
你可以通过以下用法使用这个 loader
module.loaders
对象中配置 json5-loader
;json5-loader!
前缀。假设我们有下面这个 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'
module.exports = { module: { loaders: [ { test: /\.json$/, loader: 'json-loader' } ] } }
如果需要在 Node.js 中使用,不要忘记兼容(polyfill) require。更多参考 webpack 文档。
推荐手册