Skip to content

Commit 187237a

Browse files
Implement Webpack "resolve aliases" for project source paths
See GH-26 for details about the structure concept. References: https://webpack.js.org/configuration/resolve/#resolve-alias GH-31
1 parent b18dfdb commit 187237a

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

.gatsby/onCreateBabelConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* Allows to let plugins extend/mutate the project's Babel configuration.
1313
* @author Arctic Ice Studio <[email protected]>
1414
* @author Sven Greb <[email protected]>
15-
* @see https://gatsbyjs.org/docs/node-apis/#onCreateBabelConfig
1615
* @see https://babeljs.io
1716
* @since 0.1.0
1817
*/
@@ -21,7 +20,8 @@
2120
* Implementation of the Gatsby Node `onCreateBabelConfig` API.
2221
*
2322
* @method onCreateBabelConfig
24-
* @param {object} actions Collection functions provided by Gatsby used to manipulate the state of the build process.
23+
* @param {object} actions Collection of functions provided by Gatsby used to manipulate the state of the build
24+
* process.
2525
* @see https://gatsbyjs.org/docs/node-apis/#onCreateBabelConfig
2626
* @see https://gatsbyjs.org/docs/actions
2727
* @since 0.1.0

.gatsby/onCreateWebpackConfig.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
3+
* Copyright (C) 2018-present Sven Greb <[email protected]>
4+
*
5+
* Project: Nord Docs
6+
* Repository: https://github.com/arcticicestudio/nord-docs
7+
* License: MIT
8+
*/
9+
10+
/**
11+
* @file Implementation of Gatsby Node `onCreateWebpackConfig` API.
12+
* Allows to let plugins extend/mutate the project's webpack configuration.
13+
* @author Arctic Ice Studio <[email protected]>
14+
* @author Sven Greb <[email protected]>
15+
* @see https://webpack.js.org
16+
* @since 0.1.0
17+
*/
18+
19+
const { resolve: resolvePath } = require("path");
20+
21+
const r = m => resolvePath(__dirname, m);
22+
23+
/**
24+
* Implementation of the Gatsby Node `onCreateWebpackConfig` API.
25+
*
26+
* @method onCreateWebpackConfig
27+
* @param {object} actions Collection of functions provided by Gatsby used to manipulate the state of the build
28+
* process.
29+
* @see https://gatsbyjs.org/docs/node-apis/#onCreateWebpackConfig
30+
* @see https://gatsbyjs.org/docs/actions/#setWebpackConfig
31+
* @since 0.1.0
32+
*/
33+
const onCreateWebpackConfig = ({ actions }) => {
34+
actions.setWebpackConfig({
35+
resolve: {
36+
alias: {
37+
assets: r("../src/assets/"),
38+
atoms: r("../src/components/atoms/"),
39+
config: r("../src/config/"),
40+
containers: r("../src/components/containers/"),
41+
data: r("../src/data/"),
42+
layouts: r("../src/components/layouts/"),
43+
molecules: r("../src/components/molecules/"),
44+
organisms: r("../src/components/organisms/"),
45+
pages: r("../src/components/pages/"),
46+
stores: r("../src/stores/"),
47+
styles: r("../src/styles/"),
48+
templates: r("../src/components/templates/"),
49+
utils: r("../src/utils/")
50+
}
51+
}
52+
});
53+
};
54+
55+
module.exports = onCreateWebpackConfig;

gatsby-node.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* @author Arctic Ice Studio <[email protected]>
1313
* @author Sven Greb <[email protected]>
1414
* @see https://gatsbyjs.org/docs/node-apis
15+
* @since 0.1.0
1516
*/
1617

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

0 commit comments

Comments
 (0)