Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-plugin-root-import

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-root-import - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

8

gatsby-node.js

@@ -32,10 +32,2 @@ "use strict";

}
};
exports.modifyWebpackConfig = function (_ref2, pluginOptions) {
var config = _ref2.config;
var root = pluginOptions.root || config._config.context;
config.merge({ resolve: { root: root } });
return config;
};

2

package.json
{
"name": "gatsby-plugin-root-import",
"description": "Gatsby plugin to set Webpack to resolve import root",
"version": "1.0.2",
"version": "2.0.0",
"license": "MIT",

@@ -6,0 +6,0 @@ "author": "Mong-Kuen Sun <mongkuen.sun@gmail.com>",

# gatsby-plugin-root-import
Updated to be compatiable with Gatsby v1 and Gatsby v2
Set Webpack to resolve root, allowing you to import modules from an absolute project path rather than relative `../../` paths.
## Install
**NOTE:** Plugin has different installation and usage instructions to support both Gatsby V1 and V2.
<hr/>
## Gatsby V2 Instructions
### Install
1. Install the `gatsby-plugin-root-import` plugin:
`npm install --save-dev gatsby-plugin-root-import`
`npm install --save-dev gatsby-plugin-root-import@2.0.0`
or
`yarn add --dev gatsby-plugin-root-import`
`yarn add --dev gatsby-plugin-root-import@2.0.0`
## Usage
Add into `gatsby-config.js`.
```javascript
// gatsby-config.js
module.exports = {
plugins: [
'gatsby-plugin-root-import'
]
}
```
## Gatsby V1
### Default Settings
Webpack v4 drops `resolve.root` in favor of `resolve.alias` found [here](https://webpack.js.org/configuration/resolve/#resolve-alias).
If no options are specified, the plugin defaults to your project root folder.
If no options are specified, the plugin creates a default alias of `src` to your project `src` folder.

@@ -46,6 +35,6 @@ This means you should be able to import modules like such:

You can pass a `root` option. You can specify your own folder, such as `src`.
This option corresponds with Webpack v3's `resolve.root` found [here](https://github.com/webpack/docs/wiki/configuration#resolveroot).
This may be both a directory string, or an array of directory strings.
You can pass as many keys as you want into the plugin options, and they will map to Webpack's `alias` configuration.
`alias` takes an object with keys of your alias names, and values of directory strings [like so](https://webpack.js.org/configuration/resolve/#resolve-alias).
```javascript

@@ -58,5 +47,6 @@ // gatsby-config.js

{
resolve: 'gatsby-plugin-root-import',
resolve: 'DEV-gatsby-plugin-root-import',
options: {
root: path.join(__dirname, 'src')
src: path.join(__dirname, 'src'),
pages: path.join(__dirname, 'src/pages')
}

@@ -68,15 +58,46 @@ }

This means you can import modules with project's `src` folder as `root`:
This means you should be able to import modules like such:
```javascript
// from the 'src' alias
// importing gatsbyProject/src/yourFolder/YourComponent.js
import YourComponent from 'yourFolder/YourComponent'
import YourComponent from 'src/yourFolder/YourComponent'
// from the 'pages' alias
// importing gatsbyProject/src/pages/YourPage.js
import YourPage from 'pages/YourPage'
```
## Gatsby V2
<hr/>
## Gatsby V1 Instructions
### Install
1. Install the `gatsby-plugin-root-import` plugin:
`npm install --save-dev --save-exact gatsby-plugin-root-import@1.0.0`
or
`yarn add --dev gatsby-plugin-root-import@1.0.0`
### Usage
Add into `gatsby-config.js`.
```javascript
// gatsby-config.js
module.exports = {
plugins: [
'gatsby-plugin-root-import'
]
}
```
### Default Settings
Webpack v4 drops `resolve.root` in favor of `resolve.alias` found [here](https://webpack.js.org/configuration/resolve/#resolve-alias).
If no options are specified, the plugin creates a default alias of `src` to your project `src` folder.
If no options are specified, the plugin defaults to your project root folder.

@@ -92,6 +113,6 @@ This means you should be able to import modules like such:

You can pass as many keys as you want into the plugin options, and they will map to Webpack's `alias` configuration.
You can pass a `root` option. You can specify your own folder, such as `src`.
This option corresponds with Webpack v3's `resolve.root` found [here](https://github.com/webpack/docs/wiki/configuration#resolveroot).
This may be both a directory string, or an array of directory strings.
`alias` takes an object with keys of your alias names, and values of directory strings.
```javascript

@@ -104,6 +125,5 @@ // gatsby-config.js

{
resolve: 'DEV-gatsby-plugin-root-import',
resolve: 'gatsby-plugin-root-import',
options: {
src: path.join(__dirname, 'src'),
pages: path.join(__dirname, 'src/pages')
root: path.join(__dirname, 'src')
}

@@ -115,18 +135,7 @@ }

This means you should be able to import modules like such:
This means you can import modules with project's `src` folder as `root`:
```javascript
// from the 'src' alias
// importing gatsbyProject/src/yourFolder/YourComponent.js
import YourComponent from 'src/yourFolder/YourComponent'
import YourComponent from 'yourFolder/YourComponent'
```
and
```javascript
// from the 'pages' alias
// importing gatsbyProject/src/pages/YourPage.js
import YourPage from 'pages/YourPage'
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc