W3cubDocs

/webpack 2

json-loader

Install

npm install --save-dev json-loader

Usage

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.json$/,
        use: 'json-loader'
      }
    ]
  }
}
import json from 'file.json';

CLI

webpack --module-bind 'json=json-loader'
import json from 'file.json';

Inline

import json from 'json-loader!file.json';

Options

stringify

By default, the json-loader will output the json object, set this query parameter to 'true' can output the json object as a string, e.g. require('json-loader?stringify!../index.json').

© 2012–2016 Tobias Koppers
Licensed under the Creative Commons Attribution License 4.0.
https://webpack.js.org/loaders/json-loader/