Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
gatsby-plugin-alias-imports
Advanced tools
Gatsby plugin for aliasing path locations when importing files.
This Gatsby plugin is a wrapper around the webpack feature for aliasing in your import statements.
So you can do
import '@components/navbar'
Instead of
import '../../components/navbar.js'
This works by simply injecting the options into Webpack using onCreateWebpackConfig
.
npm i --save gatsby-plugin-alias-imports
yarn add gatsby-plugin-alias-imports
Add the plugin to your Gatsby config.
{
plugins: [
{
resolve: `gatsby-plugin-alias-imports`,
options: {
alias: {},
extensions: []
}
}
]
}
Alias should be an object that takes multiple key/value pairs.
The key should be the alias and the value is the path.
The path that you specify can be relative to the root directory or absolute.
To use an absolute directory, you can do something like
const path = require('path')
// [ ... ]
alias: {
"@components": path.resolve(__dirname, 'src/components')
}
The extensions allows you to omit extensions when importing files.
It is an array of desired extensions to auto-find.
E.g. js
, css
, sass
, md
{
plugins: [
{
resolve: `gatsby-plugin-alias-imports`,
options: {
alias: {
"@src": "src",
"@components": "src/components",
"@layouts": "src/layouts",
"@pages": "src/pages",
"@sass": "src/sass",
"@templates": "src/templates",
"@posts": "content/posts",
},
extensions: [
"js",
],
}
}
]
}
import Layout from '@layouts/main'
import { ComponentA, ComponentB } from '@components/myfile'
Check out the resolve section of the Webpack config documentation for more information.
1.0.5
Minor readme fixes.
<a name="1.0.4"></a>
FAQs
Gatsby plugin for aliasing path locations when importing files.
The npm package gatsby-plugin-alias-imports receives a total of 11,214 weekly downloads. As such, gatsby-plugin-alias-imports popularity was classified as popular.
We found that gatsby-plugin-alias-imports demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.