Is it possible to Load external json file in angular-cli using json loader with out editing default webpack-config.json file ?
-
yeah it is possible without editing webpack.config.js.Chandru– Chandru2017-09-08 07:13:33 +00:00Commented Sep 8, 2017 at 7:13
-
do you have a sample .I tried adding in the assetsdockerrrr– dockerrrr2017-09-08 07:51:52 +00:00Commented Sep 8, 2017 at 7:51
-
ReferenceError: require is not defineddockerrrr– dockerrrr2017-09-08 08:00:12 +00:00Commented Sep 8, 2017 at 8:00
Add a comment
|
1 Answer
Of course, you can load JSONs, that's why you have json-loader. In the service that loads the json write this line:
import * as someName from './somePath/someFile.json;
This line may throw an error:
[ts] cannot find module './somePath/someFile.json'.
That not a real error (if the path and file name are correct), but only a typescript-type error that easily can be fixed by adding this line to your typings.d.ts file (if you don't have this file you can create it under the src folder in your solution):
/* allow import .json files */
declare module "*.json"
{
const value: any;
export default value;
}