package
json5 loader module for webpack
npm install json5-loaderGitHub-flavored package documentation.
Across all versions, last 30 days.
82,341 in 30 days
Runtime metadata.
Tagged topics.
A webpack loader for parsing json5 files into JavaScript objects.
To begin, you'll need to install json5-loader:
$ npm install json5-loader --save-devYou can use the loader either:
json5-loader in the module.rules object of the webpack configuration, orjson5-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',
},
],
},
};| Name | Type | Default | Description |
|---|---|---|---|
esModule | {Boolean} | true | Uses ES modules syntax |
esModuleType: 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',
},
],
},
};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.
Please take a moment to read our contributing guidelines if you haven't yet done so.
sokra
tobias.koppers@googlemail.com
Estimated unpacked size across 12 packages.
1.9 MB
Includes dependencies.
3 direct · 2 outdated