Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install missing dependencies (with --preact or --inferno flag) + Yarn support #214

Closed
wants to merge 13 commits into from
Next Next commit
Support use of demo/public/ for static content
  • Loading branch information
insin committed Dec 13, 2016
commit 2b012c76b9b6e54074daba64a046bd46b17382bf
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**Changed:**

* The default build for a React component demo app now supports use of a `demo/public/` directory for static content.

# 0.13.6 / 2016-12-13

**Fixed:**
Expand Down
2 changes: 1 addition & 1 deletion docs/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Passing an argument for `entry` allows you to customise the entry point for the
- By default, and ES6 modules build will be created in `es/`
- If enabled, UMD builds will be created in `umd/`

If the module has a `demo/` directory, running `build` will also create a static build of its demo app in `demo/dist/`. You can disable this by passing a `--no-demo` flag.
If the module has a `demo/` directory, running `build` will also create a static build of its demo app in `demo/dist/`. You can disable this by passing a `--no-demo` flag. If you need to use static content in the demo app, the demo build supports use of a `demo/public/` directory.

React components created as ES6 classes or functional components will have any `propTypes` they declare wrapped an `process.env.NODE_ENV !== 'production'` check, so they will be removed by dead-code elimination in the production build of any apps they're used in. You can disable this by passing a `--no-proptypes` flag.

Expand Down
20 changes: 14 additions & 6 deletions src/commands/build-demo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path'

import glob from 'glob'
import ora from 'ora'

import webpackBuild from '../webpackBuild'
Expand All @@ -12,13 +13,11 @@ import cleanDemo from './clean-demo'
export default function buildDemo(args, cb) {
let pkg = require(path.resolve('package.json'))

let dist = path.resolve('demo/dist')
let production = process.env.NODE_ENV === 'production'
let filenamePattern = production ? '[name].[chunkhash:8].js' : '[name].js'

cleanDemo(args)

let spinner = ora('Building demo').start()
webpackBuild(args, {
let config = {
babel: {
commonJSInterop: true,
presets: ['react'],
Expand All @@ -30,15 +29,24 @@ export default function buildDemo(args, cb) {
output: {
filename: filenamePattern,
chunkFilename: filenamePattern,
path: path.resolve('demo/dist'),
path: dist,
},
plugins: {
html: {
mountId: 'demo',
title: `${pkg.name} ${pkg.version} Demo`,
},
},
}, (err, stats) => {
}

if (glob.sync('demo/public/').length !== 0) {
config.plugins.copy = [{from: path.resolve('demo/public/'), to: dist}]
}

cleanDemo(args)

let spinner = ora('Building demo').start()
webpackBuild(args, config, (err, stats) => {
if (err) {
spinner.fail()
return cb(err)
Expand Down