Skip to content

Commit 640aee6

Browse files
committed
Use babel-cli on webpack config so we can use modules. Simplify and remove unnecessary host module.
1 parent 84f39e6 commit 640aee6

File tree

11 files changed

+112
-99
lines changed

11 files changed

+112
-99
lines changed

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "react-redux-starter",
3-
"description": "A universal starter kit built with ES2015, react, react-router and redux. Server rendering with react and express. Bundled with Webpack with hot module and css reloading with SCSS support.",
4-
"version": "1.0.0",
2+
"name": "universal-react-redux",
3+
"description": "A universal starter kit built with ES2015, react, react-router and redux. Server rendering with react and express. Bundled with Webpack with HMR transforms and css-modules support.",
4+
"version": "2.0.0",
55
"license": "MIT",
66
"main": "client/index.js",
77
"config": {
@@ -19,9 +19,9 @@
1919
"start": "npm run dev:build && npm run dev:start",
2020
"dev:start": "npm run dev:start:client & npm run dev:start:server",
2121
"dev:start:server": "NODE_ENV=development $(npm bin)/nodemon server",
22-
"dev:start:client": "NODE_ENV=development node webpack/dev.hot",
23-
"dev:build": "NODE_ENV=development $(npm bin)/webpack --progress --colors --display-error-details --config webpack/dev.js",
24-
"prod:build": "NODE_ENV=production $(npm bin)/webpack -p --optimize-dedupe --config webpack/prod.js",
22+
"dev:start:client": "NODE_ENV=development $(npm bin)/babel-node webpack/development.hot",
23+
"dev:build": "NODE_ENV=development $(npm bin)/babel-node $(npm bin)/webpack --progress --colors --display-error-details --config webpack/development.js",
24+
"prod:build": "NODE_ENV=production $(npm bin)/babel-node $(npm bin)/webpack -p --optimize-dedupe --config webpack/production.js",
2525
"prod:start": "NODE_ENV=production pm2 start server --name='callai'",
2626
"test": "$(npm bin)/mocha --recursive --compilers js:babel-register",
2727
"test:all": "$(npm bin)/mocha --recursive --compilers js:babel-register $(find . -path ./node_modules -prune -o -name '*.test.js' -print)",
@@ -42,14 +42,14 @@
4242
"redux-devtools": "3.3.1",
4343
"redux-devtools-dock-monitor": "1.1.1",
4444
"redux-devtools-log-monitor": "1.0.11",
45-
"webpack-dashboard": "0.1.8",
46-
"webpack-dev-server": "1.15.0",
45+
"webpack-dev-server": "1.15.1",
4746
"webpack-sources": "0.1.2"
4847
},
4948
"dependencies": {
5049
"app-module-path": "1.1.0",
51-
"autoprefixer": "6.4.0",
50+
"autoprefixer": "6.4.1",
5251
"babel": "6.5.2",
52+
"babel-cli": "6.14.0",
5353
"babel-core": "6.14.0",
5454
"babel-loader": "6.2.5",
5555
"babel-plugin-react-transform": "2.0.2",
@@ -69,30 +69,30 @@
6969
"compression-webpack-plugin": "0.3.1",
7070
"css-loader": "0.24.0",
7171
"css-modules-require-hook": "4.0.2",
72-
"express": "4.14.0",
7372
"expose-loader": "0.7.1",
73+
"express": "4.14.0",
7474
"extract-text-webpack-plugin": "1.0.1",
7575
"file-loader": "0.9.0",
7676
"font-awesome": "4.6.3",
77-
"history": "3.0.0",
77+
"history": "3.2.1",
7878
"include-media": "1.4.8",
7979
"isomorphic-fetch": "2.2.1",
8080
"json-loader": "0.5.4",
8181
"lodash": "4.15.0",
82-
"node-sass": "3.8.0",
8382
"mocha": "3.0.2",
84-
"postcss-loader": "0.11.0",
83+
"node-sass": "3.9.0",
84+
"postcss-loader": "0.11.1",
8585
"react": "15.3.1",
8686
"react-dom": "15.3.1",
8787
"react-redux": "4.4.5",
8888
"react-router": "2.7.0",
8989
"react-router-redux": "4.0.5",
90-
"redux": "3.5.2",
90+
"redux": "3.6.0",
9191
"redux-localstorage": "0.4.1",
9292
"redux-thunk": "2.1.0",
9393
"reselect": "2.5.3",
9494
"resolve-url-loader": "1.6.0",
95-
"sass-loader": "4.0.0",
95+
"sass-loader": "4.0.1",
9696
"serve-static": "1.11.1",
9797
"style-loader": "0.13.1",
9898
"url-loader": "0.5.7",

server/config.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
'use strict';
22

3-
const configFile = process.env.NODE_ENV === 'development' ? 'dev' : 'prod';
4-
const webpackConfig = require(`../webpack/${configFile}`);
5-
6-
import p from '../package.json';
3+
const isDev = process.env.NODE_ENV === 'development';
4+
const configFile = isDev ? 'development' : 'production';
5+
const webpackConfig = require(`../webpack/${configFile}`).default;
6+
const applicationPort = process.env.APPLICATION_PORT || (isDev ? 3000 : 80);
7+
import packageJson from '../package.json';
78

89
export default {
9-
name: p.name,
10-
description: p.description,
11-
version: p.version,
10+
name: packageJson.name,
11+
description: packageJson.description,
12+
version: packageJson.version,
1213

1314
// launch environment
14-
port: process.env.PORT || 3000,
15+
port: applicationPort,
1516
assetHost: process.env.ASSET_HOST || webpackConfig.output.publicPath
1617
};

server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ const basePath = require('path').resolve(__dirname, '..');
1717
const ISOTools = require('webpack-isomorphic-tools');
1818

1919
// this global variable will be used later in express middleware
20-
global.ISOTools = new ISOTools(require('../webpack/iso'))
20+
global.ISOTools = new ISOTools(require('../webpack/isomorphic').default)
2121
.development(process.env.NODE_ENV === 'development')
2222
.server(basePath, () => require('./server'));

webpack/base.js

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
1-
const path = require('path');
2-
const webpack = require('webpack');
3-
const mapValues = require('lodash/mapValues');
4-
const autoprefixer = require('autoprefixer');
5-
const isomorphicConfig = require('./iso');
6-
const IsomorphicPlugin = require('webpack-isomorphic-tools/plugin');
7-
const host = require('./host')();
1+
import path from 'path';
2+
import webpack from 'webpack';
3+
import mapValues from 'lodash/mapValues';
4+
import autoprefixer from 'autoprefixer';
5+
import isomorphicConfig from './isomorphic';
6+
import IsomorphicPlugin from 'webpack-isomorphic-tools/plugin';
7+
import { OUTPUT_PATH, ASSET_HOST, RESOLVE_PATHS } from './config';
88

99
const isDev = process.env.NODE_ENV === 'development';
1010
const isomorphicPlugin = new IsomorphicPlugin(isomorphicConfig).development(isDev);
1111

12-
const resolvePaths = {
13-
actions: 'common/js/actions',
14-
components: 'common/js/components',
15-
containers: 'common/js/containers',
16-
constants: 'common/js/constants',
17-
css: 'common/css',
18-
fonts: 'common/fonts',
19-
images: 'common/images',
20-
layouts: 'common/layouts',
21-
lib: 'common/js/lib',
22-
middleware: 'common/js/middleware',
23-
reducers: 'common/js/reducers',
24-
routes: 'common/js/routes',
25-
selectors: 'common/js/selectors',
26-
store: 'common/js/store'
27-
};
28-
29-
module.exports = {
12+
export default {
3013
context: path.resolve(__dirname, '..'),
3114
entry: {
3215
vendor: [
3316
'babel-polyfill',
3417
'classnames',
3518
'history',
3619
'lodash',
37-
'jquery',
3820
'react',
3921
'react-dom',
4022
'react-redux',
@@ -50,13 +32,13 @@ module.exports = {
5032
]
5133
},
5234
output: {
53-
path: path.join(__dirname, ('../' + host.OUTPUT_PATH)),
35+
path: path.join(__dirname, ('../' + OUTPUT_PATH)),
5436
filename: '[name].js',
55-
publicPath: host.ASSET_HOST
37+
publicPath: ASSET_HOST
5638
},
5739
resolve: {
5840
extensions: ['', '.js', '.jsx', '.scss'],
59-
alias: mapValues(resolvePaths, (str) => (
41+
alias: mapValues(RESOLVE_PATHS, (str) => (
6042
path.join(process.cwd(), ...str.split('/'))
6143
))
6244
},

webpack/config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* The webpack dev server's port to use
2+
*/
3+
export const DEV_SERVER_PORT = process.env.DEV_SERVER_PORT || 3001;
4+
5+
/* The hostname to use for the webpack dev server
6+
*/
7+
export const DEV_SERVER_HOSTNAME = process.env.DEV_SERVER_HOSTNAME || 'localhost';
8+
9+
/* The URL of the dev server including the hostname and port
10+
*/
11+
export const DEV_SERVER_HOST_URL = `http://${DEV_SERVER_HOSTNAME}:${DEV_SERVER_PORT}`;
12+
13+
/* The output path of the completed webpack build
14+
*/
15+
export const OUTPUT_PATH = process.env.OUTPUT_PATH || 'dist/';
16+
17+
/* The asset host to use inside the built webpack files. In product, set the
18+
* ASSET_HOST environment variable.
19+
*/
20+
export const ASSET_HOST = process.env.ASSET_HOST || (DEV_SERVER_HOST_URL + '/' + OUTPUT_PATH);
21+
22+
/* Paths for webpack to resolve into non-relative directories, so that instead
23+
* of having to use relative paths:
24+
*
25+
* import SomeComponents from '../../../../SomeComponent';
26+
*
27+
* we can write this instead:
28+
*
29+
* import SomeComponent from 'components/SomeComponent';
30+
*/
31+
export const RESOLVE_PATHS = {
32+
actions: 'common/js/actions',
33+
components: 'common/js/components',
34+
containers: 'common/js/containers',
35+
constants: 'common/js/constants',
36+
css: 'common/css',
37+
fonts: 'common/fonts',
38+
images: 'common/images',
39+
layouts: 'common/layouts',
40+
lib: 'common/js/lib',
41+
middleware: 'common/js/middleware',
42+
reducers: 'common/js/reducers',
43+
routes: 'common/js/routes',
44+
selectors: 'common/js/selectors',
45+
store: 'common/js/store'
46+
};

webpack/dev.hot.js renamed to webpack/development.hot.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
/* eslint-disable no-console */
2-
const webpack = require('webpack');
3-
const WebpackDevServer = require('webpack-dev-server');
4-
const baseConfig = require('./base');
5-
const host = require('./host')();
6-
const p = require('../package.json');
2+
import { DEV_SERVER_PORT, DEV_SERVER_HOSTNAME, DEV_SERVER_HOST_URL } from './config';
3+
import WebpackDevServer from 'webpack-dev-server';
4+
import webpack from 'webpack';
5+
import baseConfig from './base';
6+
import packageJson from '../package.json';
77

8+
// Webpack Entry Point for dev server
89
const entry = [
9-
'webpack-dev-server/client?' + host.HOST_URL,
10+
'webpack-dev-server/client?' + DEV_SERVER_HOST_URL,
1011
'webpack/hot/only-dev-server'
1112
];
1213

14+
// Additional plugins
1315
const plugins = [
1416
new webpack.optimize.OccurenceOrderPlugin(),
1517
new webpack.HotModuleReplacementPlugin(),
1618
new webpack.NoErrorsPlugin()
1719
];
1820

21+
// Additional loaders
1922
const loaders = [
2023
{
2124
test: /\.css$/,
2225
loaders: [
2326
'style',
24-
`css?modules&importLoaders=3&localIdentName=${p.config.css}`,
27+
`css?modules&importLoaders=3&localIdentName=${packageJson.config.css}`,
2528
'postcss',
2629
],
2730
},
2831
{
2932
test: /\.scss$/,
3033
loaders: [
3134
'style',
32-
`css?modules&importLoaders=3&localIdentName=${p.config.css}`,
35+
`css?modules&importLoaders=3&localIdentName=${packageJson.config.css}`,
3336
'postcss',
3437
'sass'
3538
]
@@ -58,7 +61,7 @@ const loaders = [
5861

5962
const config = Object.assign({}, baseConfig, {
6063
eslint: { configFile: './.eslintrc' },
61-
devServerPort: host.PORT,
64+
devServerPort: DEV_SERVER_PORT,
6265
devtool: 'eval',
6366
entry: Object.assign({}, baseConfig.entry, {
6467
app: [
@@ -79,7 +82,6 @@ const config = Object.assign({}, baseConfig, {
7982
});
8083

8184
console.info('Firing up Webpack dev server...');
82-
console.log(host);
8385

8486
new WebpackDevServer(webpack(config), {
8587
publicPath: config.output.publicPath,
@@ -95,10 +97,10 @@ new WebpackDevServer(webpack(config), {
9597
chunks: false,
9698
children: false
9799
}
98-
}).listen(host.PORT, host.HOSTNAME, function errorCallback(err) {
100+
}).listen(DEV_SERVER_PORT, DEV_SERVER_HOSTNAME, function errorCallback(err) {
99101
if (err) {
100102
console.error(err);
101103
} else {
102-
console.info('🚧 Webpack client dev-server listening on ' + host.HOST_URL + ' with publicPath:' + config.output.publicPath);
104+
console.info('🚧 Webpack client dev-server listening on ' + DEV_SERVER_HOST_URL + ' with publicPath:' + config.output.publicPath);
103105
}
104106
});

webpack/dev.js renamed to webpack/development.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const baseConfig = require('./base');
2-
const ExtractTextPlugin = require('extract-text-webpack-plugin');
3-
const p = require('../package.json');
1+
import baseConfig from './base';
2+
import ExtractTextPlugin from 'extract-text-webpack-plugin';
3+
import packageJson from '../package.json';
44

55
const plugins = [
66
new ExtractTextPlugin('styles.css')
@@ -16,22 +16,23 @@ const loaders = [
1616
test: /\.css$/,
1717
loader: ExtractTextPlugin.extract(
1818
'style',
19-
`css?minimize&modules&importLoaders=1&localIdentName=${p.config.css}` +
19+
`css?minimize&modules&importLoaders=1&localIdentName=${packageJson.config.css}` +
2020
'!postcss'
2121
)
2222
},
2323
{
2424
test: /\.scss$/,
2525
loader: ExtractTextPlugin.extract(
2626
'style',
27-
`css?minimize&modules&importLoaders=1&localIdentName=${p.config.css}` +
27+
`css?minimize&modules&importLoaders=1&localIdentName=${packageJson.config.css}` +
2828
'!postcss' +
2929
'!sass'
3030
)
3131
}
3232
];
3333

34-
module.exports = Object.assign({}, baseConfig, {
34+
export default {
35+
...baseConfig,
3536
eslint: { configFile: './.eslintrc' },
3637
devtool: 'source-map',
3738
plugins: [
@@ -44,4 +45,4 @@ module.exports = Object.assign({}, baseConfig, {
4445
...loaders
4546
]
4647
})
47-
});
48+
};

webpack/host.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

webpack/iso.js renamed to webpack/isomorphic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
assets: {
33
images: {
44
extensions: [

0 commit comments

Comments
 (0)