Skip to content

Commit e563b20

Browse files
authored
Fix local development paths (#52)
Local npm start and npm run build got broken by #33
1 parent a6edb52 commit e563b20

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

config/webpack.config.dev.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,29 @@ var autoprefixer = require('autoprefixer');
1212
var webpack = require('webpack');
1313
var HtmlWebpackPlugin = require('html-webpack-plugin');
1414

15+
// TODO: hide this behind a flag and eliminate dead code on eject.
16+
// This shouldn't be exposed to the user.
1517
var isInNodeModules = 'node_modules' ===
1618
path.basename(path.resolve(path.join(__dirname, '..', '..')));
17-
var relative = isInNodeModules ? '../../..' : '..';
19+
var relativePath = isInNodeModules ? '../../..' : '..';
20+
if (process.argv[2] === '--debug-template') {
21+
relativePath = '../template';
22+
}
23+
var srcPath = path.resolve(__dirname, relativePath, 'src');
24+
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
25+
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
26+
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
1827

1928
module.exports = {
2029
devtool: 'eval',
2130
entry: [
2231
require.resolve('webpack-dev-server/client') + '?http://localhost:3000',
2332
require.resolve('webpack/hot/dev-server'),
24-
'./src/index'
33+
path.join(srcPath, 'index')
2534
],
2635
output: {
2736
// Next line is not used in dev but WebpackDevServer crashes without it:
28-
path: path.join(__dirname, relative, 'build'),
37+
path: buildPath,
2938
pathinfo: true,
3039
filename: 'bundle.js',
3140
publicPath: '/'
@@ -34,27 +43,27 @@ module.exports = {
3443
extensions: ['', '.js'],
3544
},
3645
resolveLoader: {
37-
root: path.join(__dirname, '..', 'node_modules'),
46+
root: nodeModulesPath,
3847
moduleTemplates: ['*-loader']
3948
},
4049
module: {
4150
preLoaders: [
4251
{
4352
test: /\.js$/,
4453
loader: 'eslint',
45-
include: path.resolve(__dirname, relative, 'src'),
54+
include: srcPath,
4655
}
4756
],
4857
loaders: [
4958
{
5059
test: /\.js$/,
51-
include: path.resolve(__dirname, relative, 'src'),
60+
include: srcPath,
5261
loader: 'babel',
5362
query: require('./babel.dev')
5463
},
5564
{
5665
test: /\.css$/,
57-
include: path.resolve(__dirname, relative, 'src'),
66+
include: srcPath,
5867
loader: 'style!css!postcss'
5968
},
6069
{
@@ -81,7 +90,7 @@ module.exports = {
8190
plugins: [
8291
new HtmlWebpackPlugin({
8392
inject: true,
84-
template: path.resolve(__dirname, relative, 'index.html'),
93+
template: indexHtmlPath,
8594
}),
8695
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"development"' }),
8796
// Note: only CSS is currently hot reloaded

config/webpack.config.prod.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@ var webpack = require('webpack');
1313
var HtmlWebpackPlugin = require('html-webpack-plugin');
1414
var ExtractTextPlugin = require('extract-text-webpack-plugin');
1515

16+
// TODO: hide this behind a flag and eliminate dead code on eject.
17+
// This shouldn't be exposed to the user.
1618
var isInNodeModules = 'node_modules' ===
1719
path.basename(path.resolve(path.join(__dirname, '..', '..')));
18-
var relative = isInNodeModules ? '../../..' : '..';
20+
var relativePath = isInNodeModules ? '../../..' : '..';
21+
if (process.argv[2] === '--debug-template') {
22+
relativePath = '../template';
23+
}
24+
var srcPath = path.resolve(__dirname, relativePath, 'src');
25+
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
26+
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
27+
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
1928

2029
module.exports = {
2130
bail: true,
2231
devtool: 'source-map',
23-
entry: './src/index',
32+
entry: path.join(srcPath, 'index'),
2433
output: {
25-
path: path.resolve(__dirname, relative, 'build'),
34+
path: buildPath,
2635
filename: '[name].[chunkhash].js',
2736
chunkFilename: '[name].[chunkhash].chunk.js',
2837
// TODO: this wouldn't work for e.g. GH Pages.
@@ -33,27 +42,27 @@ module.exports = {
3342
extensions: ['', '.js'],
3443
},
3544
resolveLoader: {
36-
root: path.join(__dirname, '..', 'node_modules'),
45+
root: nodeModulesPath,
3746
moduleTemplates: ['*-loader']
3847
},
3948
module: {
4049
preLoaders: [
4150
{
4251
test: /\.js$/,
4352
loader: 'eslint',
44-
include: path.resolve(__dirname, relative, 'src')
53+
include: srcPath
4554
}
4655
],
4756
loaders: [
4857
{
4958
test: /\.js$/,
50-
include: path.resolve(__dirname, relative, 'src'),
59+
include: srcPath,
5160
loader: 'babel',
5261
query: require('./babel.prod')
5362
},
5463
{
5564
test: /\.css$/,
56-
include: path.resolve(__dirname, relative, 'src'),
65+
include: srcPath,
5766
loader: ExtractTextPlugin.extract('style', 'css!postcss')
5867
},
5968
{
@@ -82,7 +91,7 @@ module.exports = {
8291
plugins: [
8392
new HtmlWebpackPlugin({
8493
inject: true,
85-
template: path.resolve(__dirname, relative, 'index.html'),
94+
template: indexHtmlPath,
8695
minify: {
8796
removeComments: true,
8897
collapseWhitespace: true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@
9191
"webpack",
9292
"webpack-dev-server"
9393
]
94-
}
94+
}

scripts/start.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var config = require('../config/webpack.config.dev');
1616
var execSync = require('child_process').execSync;
1717
var opn = require('opn');
1818

19+
// TODO: hide this behind a flag and eliminate dead code on eject.
20+
// This shouldn't be exposed to the user.
1921
var handleCompile;
2022
if (process.argv[2] === '--smoke-test') {
2123
handleCompile = function (err, stats) {

0 commit comments

Comments
 (0)