admin管理员组

文章数量:1291264

I want to import .geojson file extension just like .json files (I don't need any special parsing). as I seen in webpack docs:

Since webpack >= v2.0.0, importing of JSON files will work by default. You might still want to use this if you use a custom file extension. See the v1.0.0 -> v2.0.0 Migration Guide for more information

but when I switch documentation version to webpack 5, there is no more content about this solution.

what is best practice to have .geojson files without downloading any extra module

I want to import .geojson file extension just like .json files (I don't need any special parsing). as I seen in webpack docs:

Since webpack >= v2.0.0, importing of JSON files will work by default. You might still want to use this if you use a custom file extension. See the v1.0.0 -> v2.0.0 Migration Guide for more information

but when I switch documentation version to webpack 5, there is no more content about this solution.

what is best practice to have .geojson files without downloading any extra module

Share Improve this question asked Mar 1, 2022 at 6:54 memesomemeso 531 silver badge5 bronze badges 2
  • Try reading the file using the fs module, then use something like JSON.parse – kerolloz Commented Mar 1, 2022 at 7:01
  • @kerolloz does it helps for bundling? I want to host my final project in a web server – memeso Commented Mar 1, 2022 at 7:07
Add a ment  | 

1 Answer 1

Reset to default 8

In webpack 5 we can use "Asset Modules" to load mon files like "json", "png" etc. See for more info: https://webpack.js/guides/asset-modules/

The loader config for your case might looks like this:

{
    test: /\.geojson$/,
    type: 'json',
}

本文标签: javascriptneed for json loader in webpack 5Stack Overflow