Import JSON file in Javascript using Webpack 4

con*_*exo 2 javascript json ecmascript-6 webpack webpack-4

I have a file called generic-map.json containing the following:

[
    {
        "names": ["text", "description"],
        "map": {
            "name": "textContent",
            "target": "property",
            "type": "string"
        }
    },
    {
        "names": ["checked"],
        "map": {
            "name": "checked",
            "target": "property",
            "type": "boolean"
        }
    },
    {
        "names": ["disabled", "readonly"],
        "map": {
            "name": "disabled",
            "target": "property",
            "type": "boolean"
        }
    },
    {
        "names": ["title", "tooltip"],
        "map": {
            "name": "title",
            "target": "property",
            "type": "string"
        }
    },
    {
        "names": ["cssclass", "classname"],
        "map": {
            "name": "",
            "target": "classList",
            "type": "string"
        }
    },
    {
        "names": ["tabindex"],
        "map": {
            "name": "tabIndex",
            "target": "attribute",
            "type": "string"
        }
    }
]
Run Code Online (Sandbox Code Playgroud)

In a Javascript file I'm trying to import this file:

import generic from './generic-map.json';
Run Code Online (Sandbox Code Playgroud)

Webpack gives me the following error:

./src/utils/property-mapping/generic-map.json
Module parse failed: Unexpected token ; in JSON at position 733 while parsing near '...type": "string" } }];'
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token ; in JSON at position 733 while parsing near '...type": "string" } }];'
    at JSON.parse (<anonymous>)
Run Code Online (Sandbox Code Playgroud)

I do know that webpack does no longer need json-loader, beginning with Webpack version 2.0.0. I'm using Webpack 4.20.2.

This is what my loaders configuration looks like:

[{
    test: /(\.js)/,
    exclude: /(node_modules)/,
    loaders: ['babel-loader'],
}, {
    test: /(\.jpg|\.png)$/,
    loader: 'url-loader?limit=10000',
}]
Run Code Online (Sandbox Code Playgroud)

Art*_*hko 5

替换test: /(\.js)/test: /\.js$/test: /\.jsx?$/

由于错误的测试表达式,babel-loader 处理 .json 文件。