Skip to content

Commit 4c57ffd

Browse files
committed
feat: use module-alias over app-module-path; use symbol-aliased paths (@, $) for less confusion
1 parent 2759f6c commit 4c57ffd

File tree

22 files changed

+94
-79
lines changed

22 files changed

+94
-79
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ If using Heroku, simply add a `Procfile` in the root directory. The
7171
web: npm run serve
7272
```
7373

74+
## Path Aliases
75+
76+
In `package.json`, there is a property named `_moduleAliases`. This object
77+
defines the require() aliases used by both webpack and node.
78+
79+
Aliased paths are prefixed with one of two symbols, which denote different
80+
things:
81+
82+
`@` - paths in the `common/` folder, e.g. `@components` or `@actions`, etc.
83+
`$` - paths in the `server/` folder
84+
85+
Aliases are nice to use for convenience, and lets us avoid using relative paths
86+
in our components:
87+
88+
```
89+
// This sucks
90+
import SomeComponent from '../../../components/SomeComponent';
91+
92+
// This is way better
93+
import SomeComponent from '@components/SomeComponent';
94+
```
95+
96+
You can add additional aliases in `package.json` to your own liking.
97+
7498
## Environment Variables
7599

76100
In development mode, environment variables are loaded by `dotenv` off the `.env`

client/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import ReactDOM from 'react-dom';
55
import { Provider } from 'react-redux';
66
import { ConnectedRouter } from 'react-router-redux';
77
import createHistory from 'history/createBrowserHistory';
8-
import configureStore from 'store';
9-
import App from 'containers/App';
8+
import configureStore from '@store';
9+
import App from '@containers/App';
1010
import Loadable from 'react-loadable';
1111

1212
// Hydrate the redux store from server state.

client/styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
import 'semantic-ui-css/semantic.min.css';
33

44
// Base styles
5-
import 'css/base/index.scss';
5+
import '@css/base/index.scss';

common/js/actions/todos.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
FETCH_TODOS_REQUEST,
66
FETCH_TODOS_SUCCESS,
77
FETCH_TODOS_FAILURE
8-
} from 'constants/index';
9-
import api from 'lib/api';
10-
import generateActionCreator from 'lib/generateActionCreator';
8+
} from '@constants/index';
9+
import api from '@lib/api';
10+
import generateActionCreator from '@lib/generateActionCreator';
1111

1212
export const addTodo = generateActionCreator(ADD_TODO, 'text');
1313
export const removeTodo = generateActionCreator(REMOVE_TODO, 'id');

common/js/components/todos/TodoList/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { List } from 'semantic-ui-react';
4-
import { TodoItem } from 'components/todos';
4+
import { TodoItem } from '@components/todos';
55
import classnames from 'classnames';
66
import css from './index.scss';
77

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import TodoList from './index';
4+
5+
describe('TodoList', () => {
6+
it('renders without crashing', () => {
7+
const div = document.createElement('div');
8+
ReactDOM.render(<TodoList />, div);
9+
});
10+
});

common/js/containers/App/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react';
22
import { Switch } from 'react-router-dom';
3-
import { RouteWithSubRoutes } from 'components/common';
43
import { Container } from 'semantic-ui-react';
5-
import { Header, Footer } from 'components/common';
4+
import { Header, Footer, RouteWithSubRoutes } from '@components/common';
65
import { hot } from 'react-hot-loader';
7-
import routes from 'routes';
6+
import routes from '@routes';
87

98
const App = () => (
109
<Container fluid={false}>

common/js/containers/Todos/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
44
import { Helmet } from 'react-helmet';
5-
import * as actions from 'actions/todos';
5+
import * as actions from '@actions/todos';
66
import { Container } from 'semantic-ui-react';
7-
import { TodoList, TodoForm } from 'components/todos';
7+
import { TodoList, TodoForm } from '@components/todos';
88

99
class TodosContainer extends Component {
1010
static propTypes = {

common/js/pages/Todos/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { Component } from 'react';
22
import Loadable from 'react-loadable';
3-
import { Loading } from 'components/common';
4-
import { fetchTodos } from 'actions/todos';
3+
import { Loading } from '@components/common';
4+
import { fetchTodos } from '@actions/todos';
55

66
// NOTE: To turn off dynamic imports, import this container normally using:
7-
// import TodosContainer from 'containers/Todos';
7+
// import TodosContainer from '@containers/Todos';
88
const TodosContainer = Loadable({
99
loader: () => import('../../containers/Todos'),
1010
loading: Loading

common/js/reducers/todos.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
ADD_TODO, REMOVE_TODO, TOGGLE_TODO,
33
FETCH_TODOS_REQUEST, FETCH_TODOS_SUCCESS, FETCH_TODOS_FAILURE
4-
} from 'constants/index';
4+
} from '@constants/index';
55

66
const defaultState = {
77
todos: [],

0 commit comments

Comments
 (0)