Skip to content

Commit

Permalink
Fix local development paths
Browse files Browse the repository at this point in the history
Local npm start and npm run build got broken by #33
  • Loading branch information
gaearon committed Jul 21, 2016
1 parent a6edb52 commit 7482eea
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
25 changes: 17 additions & 8 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,29 @@ var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

// TODO: hide this behind a flag and eliminate dead code on eject.
// This shouldn't be exposed to the user.
var isInNodeModules = 'node_modules' ===
path.basename(path.resolve(path.join(__dirname, '..', '..')));
var relative = isInNodeModules ? '../../..' : '..';
var relativePath = isInNodeModules ? '../../..' : '..';
if (process.argv[2] === '--debug-template') {
relativePath = '../template';
}
var srcPath = path.resolve(__dirname, relativePath, 'src');
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');

module.exports = {
devtool: 'eval',
entry: [
require.resolve('webpack-dev-server/client') + '?http://localhost:3000',
require.resolve('webpack/hot/dev-server'),
'./src/index'
path.join(srcPath, 'index')
],
output: {
// Next line is not used in dev but WebpackDevServer crashes without it:
path: path.join(__dirname, relative, 'build'),
path: buildPath,
pathinfo: true,
filename: 'bundle.js',
publicPath: '/'
Expand All @@ -34,27 +43,27 @@ module.exports = {
extensions: ['', '.js'],
},
resolveLoader: {
root: path.join(__dirname, '..', 'node_modules'),
root: nodeModulesPath,
moduleTemplates: ['*-loader']
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint',
include: path.resolve(__dirname, relative, 'src'),
include: srcPath,
}
],
loaders: [
{
test: /\.js$/,
include: path.resolve(__dirname, relative, 'src'),
include: srcPath,
loader: 'babel',
query: require('./babel.dev')
},
{
test: /\.css$/,
include: path.resolve(__dirname, relative, 'src'),
include: srcPath,
loader: 'style!css!postcss'
},
{
Expand All @@ -81,7 +90,7 @@ module.exports = {
plugins: [
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(__dirname, relative, 'index.html'),
template: indexHtmlPath,
}),
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"development"' }),
// Note: only CSS is currently hot reloaded
Expand Down
25 changes: 17 additions & 8 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

// TODO: hide this behind a flag and eliminate dead code on eject.
// This shouldn't be exposed to the user.
var isInNodeModules = 'node_modules' ===
path.basename(path.resolve(path.join(__dirname, '..', '..')));
var relative = isInNodeModules ? '../../..' : '..';
var relativePath = isInNodeModules ? '../../..' : '..';
if (process.argv[2] === '--debug-template') {
relativePath = '../template';
}
var srcPath = path.resolve(__dirname, relativePath, 'src');
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');

module.exports = {
bail: true,
devtool: 'source-map',
entry: './src/index',
entry: path.join(srcPath, 'index'),
output: {
path: path.resolve(__dirname, relative, 'build'),
path: buildPath,
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].chunk.js',
// TODO: this wouldn't work for e.g. GH Pages.
Expand All @@ -33,27 +42,27 @@ module.exports = {
extensions: ['', '.js'],
},
resolveLoader: {
root: path.join(__dirname, '..', 'node_modules'),
root: nodeModulesPath,
moduleTemplates: ['*-loader']
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint',
include: path.resolve(__dirname, relative, 'src')
include: srcPath
}
],
loaders: [
{
test: /\.js$/,
include: path.resolve(__dirname, relative, 'src'),
include: srcPath,
loader: 'babel',
query: require('./babel.prod')
},
{
test: /\.css$/,
include: path.resolve(__dirname, relative, 'src'),
include: srcPath,
loader: ExtractTextPlugin.extract('style', 'css!postcss')
},
{
Expand Down Expand Up @@ -82,7 +91,7 @@ module.exports = {
plugins: [
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(__dirname, relative, 'index.html'),
template: indexHtmlPath,
minify: {
removeComments: true,
collapseWhitespace: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@
"webpack",
"webpack-dev-server"
]
}
}
2 changes: 2 additions & 0 deletions scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var config = require('../config/webpack.config.dev');
var execSync = require('child_process').execSync;
var opn = require('opn');

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

0 comments on commit 7482eea

Please sign in to comment.