Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
fix: vitamin start with env=production (#232)
Browse files Browse the repository at this point in the history
* fix: vitamin start with env=production
* fix: update readme about cssnext support
* fix: emoji stored in an object (no more double whitespace)
* style: eslint —fix
  • Loading branch information
alepee authored Feb 17, 2017
1 parent 666adc7 commit 8d41c83
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ What's included in the menu
- [**React**](https://github.com/facebook/react). What else ?
- [**Redux**](https://github.com/rackt/redux). The community consensus for managing application state
- [**CSS modules**](https://github.com/css-modules/css-modules) Namespace your css
- [**CSSNext**](https://github.com/MoOx/postcss-cssnext) Use tomorrow CSS syntax right now
- **Server Side Rendering**. SEO and mobile friendly, zero config needed.
- **Hot Module Reload Everywhere**. On server. On reducers. On CSS. On react app. No more `Ctrl+R`. (But without using [react-HMR](https://github.com/reactjs/redux/pull/1455))
- **Error message on the browser**. No need to switch to console anymore. Using [redbox-react](https://www.npmjs.com/package/redbox-react) and [webpack-hot-middleware](https://github.com/glenjamin/webpack-hot-middleware)
Expand Down
38 changes: 24 additions & 14 deletions bin/vitamin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { version } from '../package.json';

const DEV = process.env.NODE_ENV !== 'production';

const symbols = {
clock: '\uD83D\uDD50 ',
};

const clean = () => new Promise((resolve, reject) => {
const config = parseConfig();
Expand All @@ -31,9 +34,9 @@ const clean = () => new Promise((resolve, reject) => {

const checkHot = (hot) => {
if (hot && !DEV) {
console.log(chalk.orange(
chalk.bold('Warning: Hot module reload option ignored in production environment.'),
'(based on your NODE_ENV variable)',
console.log(chalk.yellow(
'[WARNING]: Hot module reload option ignored in production environment.\n' +
'(based on your NODE_ENV variable)\n',
));
/* eslint no-param-reassign: 0 */
return false;
Expand Down Expand Up @@ -68,7 +71,7 @@ const createCompiler = (webpackConfig, message, options) => {
const compiler = webpack(webpackConfig);
if (process.stdout.isTTY) {
const bar = new ProgressBar(
`${chalk.blue(`\uD83D\uDD50 Building ${message}...`)} :percent [:bar]`,
`${chalk.blue(`${symbols.clock} Building ${message}...`)} :percent [:bar]`,
{ incomplete: ' ', total: 60, clear: true, stream: process.stdout },
);
compiler.apply(new ProgressPlugin((percentage, msg) => {
Expand All @@ -95,19 +98,19 @@ const commonBuild = (createWebpackConfig, message, options, hotCallback, restart
};

if (!options.hot) {
const { compiler } = createCompilerCommonBuild();
const { compiler, config } = createCompilerCommonBuild();
return new Promise((resolve, reject) => (
compiler.run(buildCallback(resolve, reject))
compiler.run(buildCallback(buildStats => resolve({ config, buildStats }), reject))
));
}

let webpackWatcher;
const watch = () => (
new Promise((resolve) => {
const { compiler, config } = createCompilerCommonBuild();
const callbackWatch = buildCallback(() => {
const callbackWatch = buildCallback((buildStats) => {
hotCallback(config);
resolve(config);
resolve({ config, buildStats });
});
webpackWatcher = compiler.watch({}, callbackWatch);
})
Expand All @@ -130,12 +133,13 @@ const build = (options, hotCallback, restartServer) => (options.hot ?
)
:
commonBuild(webpackConfigClient, 'client bundle(s)', options)
.then(stats => commonBuild(
.then(({ buildStats }) => commonBuild(
webpackConfigServer, 'server bundle...',
// Cannot build in parallel because server-side rendering
// needs client bundle name in the html layout for script path
{ ...options, assetsByChunkName: stats.toJson().assetsByChunkName },
{ ...options, assetsByChunkName: buildStats.toJson().assetsByChunkName },
))
.then(({ config }) => restartServer && restartServer(config))
);


Expand All @@ -145,7 +149,7 @@ const test = ({ hot, runner, runnerArgs }) => {
throw new Error('Please specify a test file path in .vitaminrc');
}

console.log(chalk.blue('\uD83D\uDD50 Launching tests...'));
console.log(chalk.blue(`${symbols.clock} Launching tests...`));
const serverFile = path.join(
config.server.buildPath,
'tests',
Expand All @@ -158,7 +162,7 @@ const test = ({ hot, runner, runnerArgs }) => {


const serve = (config) => {
process.stdout.write(chalk.blue('\uD83D\uDD50 Launching server...'));
process.stdout.write(chalk.blue(`${symbols.clock} Launching server...`));
const serverFile = path.join(
config.server.buildPath,
config.server.filename,
Expand All @@ -184,7 +188,6 @@ const start = (options) => {
let exiting = false;
listenExitSignal((signal) => {
exiting = true;
console.log(!!serverProcess);
if (!serverProcess) process.exit();
killProcess(serverProcess, { signal }).then(() => {
console.log('exiting'); process.exit();
Expand Down Expand Up @@ -248,7 +251,14 @@ program
.alias('b')
.description('Build server and client bundles')
.option('-h, --hot', 'Activate hot module reload')
.action(({ hot }) => build({ hot: checkHot(hot) }));
.action(({ hot }) => build({ hot: checkHot(hot) })
.catch((err) => {
if (err !== BUILD_FAILED) {
console.log(err.stack || err);
}
process.exit(1);
}),
);

program
.command('clean')
Expand Down

0 comments on commit 8d41c83

Please sign in to comment.