commit 52899e83f83255b8f30968396f3300e8c1b6c3fd
parent 18aaf2ae1b09b5e467e705991dc8e3a7c7f3e5c3
Author: Vladimir Kutepov <frenzzy.man@gmail.com>
Date: Fri, 10 Feb 2017 20:33:26 +0300
Clean up tools folder
Diffstat:
9 files changed, 27 insertions(+), 42 deletions(-)
diff --git a/Dockerfile b/Dockerfile
@@ -1,10 +1,11 @@
-FROM node:7.2.1-alpine
+FROM node:6.9.5-alpine
# Copy application files
COPY ./build /usr/src/app
WORKDIR /usr/src/app
-# Install Node.js dependencies
-RUN npm install --production --silent
+# Install Yarn and Node.js dependencies
+RUN npm install yarn --global --no-progress --silent --depth 0 && \
+ yarn install --production --no-progress
CMD [ "node", "server.js" ]
diff --git a/src/client.js b/src/client.js
@@ -150,23 +150,18 @@ async function onLocationChange(location, initial) {
() => onRenderComplete(route, location),
);
} catch (error) {
- console.error(error); // eslint-disable-line no-console
-
- // Current url has been changed during navigation process, do nothing
- if (currentLocation.key !== location.key) {
- return;
- }
-
// Display the error in full-screen for development mode
if (process.env.NODE_ENV !== 'production') {
appInstance = null;
document.title = `Error: ${error.message}`;
ReactDOM.render(<ErrorReporter error={error} />, container);
- return;
+ throw error;
}
- if (!initial) {
- // Avoid broken navigation in production mode by a full page reload on error
+ console.error(error); // eslint-disable-line no-console
+
+ // Avoid broken navigation in production mode by a full page reload on error
+ if (!initial && currentLocation.key === location.key) {
window.location.reload();
}
}
diff --git a/tools/.eslintrc b/tools/.eslintrc
@@ -1,6 +1,6 @@
{
"rules": {
- "no-console": 0,
- "global-require": 0
+ "no-console": "off",
+ "global-require": "off"
}
}
diff --git a/tools/README.md b/tools/README.md
@@ -24,10 +24,11 @@
##### Options
Flag | Description
------------ | --------------------------------------------------
+----------- | --------------------------------------------------
`--release` | Minimizes and optimizes the compiled output
`--verbose` | Prints detailed information to the console
`--static` | Renders [specified routes](./render.js#L15) as static html files
+`--docker` | Build an image from a Dockerfile
For example:
@@ -44,5 +45,6 @@ $ yarn start -- --release # Launch dev server in production mode
#### Misc
* `webpack.config.js` - Webpack configuration for both client-side and server-side bundles
+* `postcss.config.js` - PostCSS configuration for transforming styles with JS plugins
* `run.js` - Helps to launch other scripts with `babel-node` (e.g. `babel-node tools/run build`)
* `.eslintrc` - ESLint overrides for built automation scripts
diff --git a/tools/copy.js b/tools/copy.js
@@ -29,13 +29,11 @@ async function copy() {
},
}, null, 2)),
copyFile('LICENSE.txt', 'build/LICENSE.txt'),
- copyDir('src/content', 'build/content'),
copyDir('public', 'build/public'),
]);
if (process.argv.includes('--watch')) {
const watcher = chokidar.watch([
- 'src/content/**/*',
'public/**/*',
], { ignoreInitial: true });
diff --git a/tools/postcss.config.js b/tools/postcss.config.js
@@ -7,8 +7,6 @@
* LICENSE.txt file in the root directory of this source tree.
*/
-/* eslint-disable global-require */
-
module.exports = () => ({
// The list of plugins for PostCSS
// https://github.com/postcss/postcss
diff --git a/tools/runServer.js b/tools/runServer.js
@@ -16,8 +16,8 @@ const RUNNING_REGEXP = /The server is running at http:\/\/(.*?)\//;
let server;
let pending = true;
-const { output } = webpackConfig.find(x => x.name === 'server');
-const serverPath = path.join(output.path, output.filename);
+const [, serverConfig] = webpackConfig;
+const serverPath = path.join(serverConfig.output.path, serverConfig.output.filename);
// Launch or restart the Node.js server
function runServer() {
diff --git a/tools/start.js b/tools/start.js
@@ -22,7 +22,7 @@ const isDebug = !process.argv.includes('--release');
process.env.NODE_ENV = isDebug ? 'development' : 'production';
process.argv.push('--watch');
-const [config] = webpackConfig;
+const [clientConfig, serverConfig] = webpackConfig;
/**
* Launches a development web server with "live reload" functionality -
@@ -34,33 +34,31 @@ async function start() {
await new Promise((resolve) => {
// Save the server-side bundle files to the file system after compilation
// https://github.com/webpack/webpack-dev-server/issues/62
- webpackConfig.find(x => x.name === 'server').plugins.push(
- new WriteFilePlugin({ log: false }),
- );
+ serverConfig.plugins.push(new WriteFilePlugin({ log: false }));
// Hot Module Replacement (HMR) + React Hot Reload
if (isDebug) {
- config.entry.client = [...new Set([
+ clientConfig.entry.client = [...new Set([
'babel-polyfill',
'react-hot-loader/patch',
'webpack-hot-middleware/client',
- ].concat(config.entry.client))];
- config.output.filename = config.output.filename.replace('[chunkhash', '[hash');
- config.output.chunkFilename = config.output.chunkFilename.replace('[chunkhash', '[hash');
- const { query } = config.module.rules.find(x => x.loader === 'babel-loader');
+ ].concat(clientConfig.entry.client))];
+ clientConfig.output.filename = clientConfig.output.filename.replace('[chunkhash', '[hash');
+ clientConfig.output.chunkFilename = clientConfig.output.chunkFilename.replace('[chunkhash', '[hash');
+ const { query } = clientConfig.module.rules.find(x => x.loader === 'babel-loader');
query.plugins = ['react-hot-loader/babel'].concat(query.plugins || []);
- config.plugins.push(new webpack.HotModuleReplacementPlugin());
- config.plugins.push(new webpack.NoEmitOnErrorsPlugin());
+ clientConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
+ clientConfig.plugins.push(new webpack.NoEmitOnErrorsPlugin());
}
const bundler = webpack(webpackConfig);
const wpMiddleware = webpackDevMiddleware(bundler, {
// IMPORTANT: webpack middleware can't access config,
// so we should provide publicPath by ourselves
- publicPath: config.output.publicPath,
+ publicPath: clientConfig.output.publicPath,
// Pretty colored output
- stats: config.stats,
+ stats: clientConfig.stats,
// For other settings see
// https://webpack.github.io/docs/webpack-dev-middleware
diff --git a/tools/webpack.config.js b/tools/webpack.config.js
@@ -167,13 +167,6 @@ const clientConfig = {
resolve: { ...config.resolve },
plugins: [
- // For compatability with old loaders
- // https://webpack.js.org/guides/migrating/#loaderoptionsplugin-context
- new webpack.LoaderOptionsPlugin({
- minimize: !isDebug,
- debug: isDebug,
- }),
-
// Define free variables
// https://webpack.github.io/docs/list-of-plugins.html#defineplugin
new webpack.DefinePlugin({