webpack-contrib / file-loader

File Loader
MIT License
1.86k stars 257 forks source link

Trying to load json file using file-loader , it work before build but when create build it just load the path of file instead of content #324

Closed mshafiqmk closed 5 years ago

mshafiqmk commented 5 years ago

Expected Behavior

should log values inside x.json file

Actual Behavior

it log name of the generated json file in the build

Code

i have created simple demo , here is the link to code repo https://github.com/shafiqkhuidad/WebpackLoaders-Demo

How Do We Reproduce?

alexander-akait commented 5 years ago

It is expected, because file-loader generate file and doesn't parse content. You don't need file-loader for json in webpack@4. Also using file-loader increase you bundle size because tree shaking doesn't work

mshafiqmk commented 5 years ago

@evilebottnawi thanks , i want to use same json file before and after build

mshafiqmk commented 5 years ago

image

if you see here the index.bundle.js file have reference to that json file ?

i have try json file-loader it just append the content of json file like that : image but i want to load this json content from file.

alexander-akait commented 5 years ago

Use javascript/auto or json https://github.com/webpack/webpack/blob/master/lib/WebpackOptionsDefaulter.js#L60

mshafiqmk commented 5 years ago

i have already try this option it doesn't work for me . It append the json file into bundle.js , i don't want this . i want to copy json file to build folder and then the generated build(bundle.js) file should use that copied file ?

alexander-akait commented 5 years ago

It is impossible, use multicompile mode

mshafiqmk commented 5 years ago

Thanks @evilebottnawi , can you please share some link or example of multiple mode ?

alexander-akait commented 5 years ago

@shafiqkhuidad looks on documentation