Skip to content

Instantly share code, notes, and snippets.

@clessg
Last active November 8, 2015 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clessg/fc0a1b4ea1c494b33c0c to your computer and use it in GitHub Desktop.
Save clessg/fc0a1b4ea1c494b33c0c to your computer and use it in GitHub Desktop.
{
...
"scripts": {
"server": "NODE_PATH=./src node ./server.js",
"build": "webpack --config webpack.config.js"
}
...
}
// Run this using `npm run server`.
// Allows us to import ES6 modules.
require('babel/register')();
var UserProfile = require('components/users/UserProfile');
// render <UserProfile />
// This file is src/components/users/UserProfile.js
import Icon from 'components/base/Icon';
import doFunStuff from 'utils/doFunStuff';
// Would normally be:
// import Icon from '../base/Icon';
// import doFunStuff from '../../utils/doFunStuff';
// This is handled by Webpack using resolve.root (or resolve.alias).
// In Node, it's handled by using NODE_PATH=./src
...
module.exports = {
...
resolve: {
// Makes require('components/base/Icon') reference src/components/base/Icon.
root: __dirname + '/src'
// Or you could manually specify aliases:
// alias: {
// 'components': __dirname + '/src/components/',
// 'utils': __dirname + '/src/utils/'
// }
}
...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment