Module
Node.js Module
Categories:
Load module with alias path
Install Packages
npm i --save module-alias
yarn add module-alias
Setting Module Alias
Setting the alias path that you want
// packages.json
// Aliases
"_moduleAliases": {
"@root" : ".", // Application's root
"@deep" : "src/some/very/deep/directory/or/file",
"@my_module" : "lib/some-file.js",
"something" : "src/foo", // Or without @. Actually, it could be any string
}
Init module alias
Add this line at the very main file of your app, before any code
require('module-alias/register')
Import module from alias
const DeepModule = require('@deep/some-module')
Load the json file and parse it
import data from '../public/data.json';
function MyComponent() {
const parsedData = JSON.parse(JSON.stringify(data));
// Use the parsed data in your component
// ...
}