Skip to content

Commit

Permalink
Implement Webpack "resolve aliases" for project source paths
Browse files Browse the repository at this point in the history
See GH-26 for details about the structure concept.

References:
  https://webpack.js.org/configuration/resolve/#resolve-alias

GH-31
  • Loading branch information
arcticicestudio committed Nov 19, 2018
1 parent b18dfdb commit 187237a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gatsby/onCreateBabelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* Allows to let plugins extend/mutate the project's Babel configuration.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @see https://gatsbyjs.org/docs/node-apis/#onCreateBabelConfig
* @see https://babeljs.io
* @since 0.1.0
*/
Expand All @@ -21,7 +20,8 @@
* Implementation of the Gatsby Node `onCreateBabelConfig` API.
*
* @method onCreateBabelConfig
* @param {object} actions Collection functions provided by Gatsby used to manipulate the state of the build process.
* @param {object} actions Collection of functions provided by Gatsby used to manipulate the state of the build
* process.
* @see https://gatsbyjs.org/docs/node-apis/#onCreateBabelConfig
* @see https://gatsbyjs.org/docs/actions
* @since 0.1.0
Expand Down
55 changes: 55 additions & 0 deletions .gatsby/onCreateWebpackConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @file Implementation of Gatsby Node `onCreateWebpackConfig` API.
* Allows to let plugins extend/mutate the project's webpack configuration.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @see https://webpack.js.org
* @since 0.1.0
*/

const { resolve: resolvePath } = require("path");

const r = m => resolvePath(__dirname, m);

/**
* Implementation of the Gatsby Node `onCreateWebpackConfig` API.
*
* @method onCreateWebpackConfig
* @param {object} actions Collection of functions provided by Gatsby used to manipulate the state of the build
* process.
* @see https://gatsbyjs.org/docs/node-apis/#onCreateWebpackConfig
* @see https://gatsbyjs.org/docs/actions/#setWebpackConfig
* @since 0.1.0
*/
const onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
assets: r("../src/assets/"),
atoms: r("../src/components/atoms/"),
config: r("../src/config/"),
containers: r("../src/components/containers/"),
data: r("../src/data/"),
layouts: r("../src/components/layouts/"),
molecules: r("../src/components/molecules/"),
organisms: r("../src/components/organisms/"),
pages: r("../src/components/pages/"),
stores: r("../src/stores/"),
styles: r("../src/styles/"),
templates: r("../src/components/templates/"),
utils: r("../src/utils/")
}
}
});
};

module.exports = onCreateWebpackConfig;
2 changes: 2 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @see https://gatsbyjs.org/docs/node-apis
* @since 0.1.0
*/

exports.onCreateBabelConfig = require("./.gatsby/onCreateBabelConfig");
exports.onCreateWebpackConfig = require("./.gatsby/onCreateWebpackConfig");

0 comments on commit 187237a

Please sign in to comment.