diff --git a/package.json b/package.json index 0744588e..1453d8dd 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "create-react-app-scripts", "version": "0.0.1", "scripts": { - "start": "node scripts/start.js", - "build": "node scripts/build.js" + "start": "node scripts/start.js local", + "build": "node scripts/build.js local" }, "dependencies": { "autoprefixer": "^6.3.7", diff --git a/scripts/build.js b/scripts/build.js index 70c2e755..0799a6b9 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -4,7 +4,9 @@ var spawnSync = require('child_process').spawnSync; var webpack = require('webpack'); var config = require('../webpack.config.prod'); -spawnSync('rm', ['-rf', 'build']); +var relative = process.argv[2] === 'local' ? '.' : '../..'; +spawnSync('rm', ['-rf', relative + '/build']); + webpack(config).run(function(err, stats) { if (err) { console.error(err); diff --git a/scripts/init.js b/scripts/init.js index 5dd1aa8b..9ba2961e 100644 --- a/scripts/init.js +++ b/scripts/init.js @@ -1,3 +1,5 @@ +var fs = require('fs'); + module.exports = function(hostPath, appName) { var selfPath = hostPath + '/node_modules/create-react-app-scripts'; @@ -11,14 +13,16 @@ module.exports = function(hostPath, appName) { // Setup the script rules hostPackage.scripts = {}; - ['start', 'build', 'publish-gh-pages'].forEach(function(command) { - hostPackage.scripts[command] = 'node node_modules/create-react-app-scripts/' + command + '.js'; + ['start', 'build'].forEach(function(command) { + hostPackage.scripts[command] = 'node node_modules/create-react-app-scripts/scripts/' + command + '.js'; }); fs.writeFileSync(hostPath + '/package.json', JSON.stringify(hostPackage, null, 2)); + // TODO: run npm install in hostPath, (not needed for npm 3 if we accept some hackery) + // Move the src folder - fs.renameSync(selfPackage + '/src', hostPackage + '/src'); + fs.renameSync(selfPath + '/src', hostPath + '/src'); console.log('Creating the app', appName, 'at', hostPath); }; diff --git a/webpack.config.dev.js b/webpack.config.dev.js index d04302c7..9dd26773 100644 --- a/webpack.config.dev.js +++ b/webpack.config.dev.js @@ -3,6 +3,8 @@ var autoprefixer = require('autoprefixer'); var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); +var relative = process.argv[2] === 'local' ? '.' : '../..'; + module.exports = { devtool: 'eval', entry: [ @@ -11,7 +13,7 @@ module.exports = { ], output: { // Next line is not used in dev but WebpackDevServer crashes without it: - path: path.join(__dirname, 'build'), + path: path.join(__dirname, relative, 'build'), filename: 'bundle.js', publicPath: '/' }, @@ -20,18 +22,18 @@ module.exports = { { test: /\.js$/, loader: 'eslint-loader', - include: path.resolve(__dirname, 'src') + include: path.resolve(__dirname, relative, 'src') } ], loaders: [ { test: /\.js$/, - include: path.resolve(__dirname, 'src'), + include: path.resolve(__dirname, relative, 'src'), loader: 'babel' }, { test: /\.css$/, - include: path.resolve(__dirname, 'src'), + include: path.resolve(__dirname, relative, 'src'), loader: 'style!css!postcss' }, { diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 0efb28a4..67fff0cf 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -3,11 +3,13 @@ var autoprefixer = require('autoprefixer'); var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); +var relative = process.argv[2] === 'local' ? '.' : '../..'; + module.exports = { devtool: 'source-map', entry: './src/index.js', output: { - path: path.join(__dirname, 'build'), + path: path.resolve(__dirname, relative, 'build'), filename: '[name].[hash].js', // TODO: this wouldn't work for e.g. GH Pages. // Good news: we can infer it from package.json :-) @@ -18,18 +20,18 @@ module.exports = { { test: /\.js$/, loader: 'eslint-loader', - include: path.resolve(__dirname, 'src') + include: path.resolve(__dirname, relative, 'src') } ], loaders: [ { test: /\.js$/, - include: path.resolve(__dirname, 'src'), + include: path.resolve(__dirname, relative, 'src'), loader: 'babel' }, { test: /\.css$/, - include: path.resolve(__dirname, 'src'), + include: path.resolve(__dirname, relative, 'src'), loader: 'style!css!postcss' }, {