Skip to content

Commit

Permalink
Make entry point and build directory configurable via arguments
Browse files Browse the repository at this point in the history
Part of #115
  • Loading branch information
insin committed Jun 3, 2016
1 parent d9ad50f commit ae59a8c
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 104 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@

**Added:**

- The entry point for apps and npm module UMD builds can now be specified as an argument to [`build` and `serve` commands](https://github.com/insin/nwb/blob/v0.11.0/docs/Commands.md#project-type-specific-commands). The default is still `src/index.js`. [[#115](https://github.com/insin/nwb/issues/115)]
- The directory web apps are built into can now be specified as an argument to [`build`, `clean` and `serve` commands](https://github.com/insin/nwb/blob/v0.11.0/docs/Commands.md#project-type-specific-commands). The default is still `dist/`.
- Added [`webpack.compat` config](https://github.com/insin/nwb/blob/v0.11.0/docs/Configuration.md#compat-object) to enable compatibility tweaks for modules which are known to be problematic with Webpack - initially this includes support for Enzyme, Moment.js and Sinon.js 1.x [[#108](https://github.com/insin/nwb/issues/108)]
- Added [`webpack.postcss` config](https://github.com/insin/nwb/blob/v0.11.0/docs/Configuration.md#postcss-object) to customise the PostCSS plugins applied to each style pipeline [[#57](https://github.com/insin/nwb/issues/57)]
- Added [`webpack.vendorBundle` config](https://github.com/insin/nwb/blob/v0.11.0/docs/Configuration.md#vendorbundle-boolean) to disable automatically extracting anything imported from `node_modules/` out into a separate `vendor` chunk [[#106](https://github.com/insin/nwb/issues/106)]
Expand Down
90 changes: 59 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,32 +132,41 @@ This video shows the resulting example of using nwb to create a new React projec
## Usage

```
Usage: nwb <command>
Usage:
nwb <command> [options]
Options:
-h, --help display this help message
-v, --version print nwb's version
Project creation commands:
init <project-type> [name]
init <project_type> [name]
initialise a project in the current directory
new <project-type> <name>
new <project_type> <name>
create a project in a new directory
-f, --force force project creation, don't ask questions
-g, --global global variable name to export in the UMD build
--no-jsnext disable npm ES6 modules build
--no-umd disable npm UMD module build
--react version of React to install for React apps and components
Positional arguments:
project_type project type - see the list below
name project name [default: current directory name]
Options:
-f, --force force project creation, don't ask questions
-g, --global global variable name to export in the UMD build
--no-jsnext disable npm ES6 modules build
--no-umd disable npm UMD module build
--react version of React to install for React apps & components
Project types:
react-app a React app
react-component a React component module with a demo app
web-app a plain JavaScript app
web-module a plain JavaScript module
Development commands:
Generic development commands:
Positional arguments for these commands depend on the type of project they're
being run in. See the applicable project-type-specific commands below.
build
clean and build the project
Expand All @@ -166,43 +175,62 @@ Development commands:
serve
serve an app, or a component's demo app, with hot reloading
--auto-install auto install missing npm dependencies
--fallback serve the index page from any path
--host hostname to bind the dev server to (default: localhost)
--info show webpack module info
--port port to run the dev server on (default: 3000)
--reload auto reload the page if hot reloading fails
Options:
--auto-install auto install missing npm dependencies
--fallback serve the index page from any path
--host hostname to bind the dev server to [default: localhost]
--info show webpack module info
--port port to run the dev server on [default: 3000]
--reload auto reload the page if hot reloading fails
test
run unit tests
--coverage create a code coverage report
--server keep running tests on every change
Project type-specific commands:
Options:
--coverage create a code coverage report
--server keep running tests on every change
Project-type-specific commands:
build-demo
build a demo app from demo/src/index.js to demo/dist/
build-module
create an ES5 build for an npm module (ES6 modules build requires config)
build-react-app
build a react app from src/index.js to dist/
build-umd
create a UMD build for an npm module (requires config)
build-web-app
build a web app from src/index.js to dist/
clean-app
delete dist/
build-react-app [entry] [dist_dir]
build a React app from entry to dist_dir
build-umd [entry]
create a UMD build for an npm module from entry (requires config)
build-web-app [entry] [dist_dir]
build a web app from entry to dist_dir
clean-app [dist_dir]
delete dist_dir
clean-demo
delete demo/dist/
clean-module
delete coverage/, es6/ and lib/
delete coverage/, es6/ and lib/
clean-umd
delete umd/
serve-react-app
serve a React app from src/index.js
serve-react-app [entry]
serve a React app from entry
serve-react-demo
serve a React demo app from demo/src/index.js
serve-web-app
serve a web app from src/index.js
serve-web-app [entry]
serve a web app from entry
Positional arguments:
entry entry point [default: src/index.js]
dist_dir build output directory [default: dist/]
```

## Versioning
Expand Down
53 changes: 36 additions & 17 deletions docs/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ These are optional, but they're a quick way to get started with a new project us
#### `new` - create a new project

```
nwb new <project-type> <name>
nwb new <project_type> <name>
```

Creates a new directory and initialises a project skeleton in it.
Expand Down Expand Up @@ -63,7 +63,7 @@ Creates a skeleton for a web module with the given name, with an optional UMD bu
#### `init` - initialise a project in the current directory

```
nwb init <project-type> [name]
nwb init <project_type> [name]
```

This is the same as `new`, except the `name` argument is optional and the new project is initialised in the current directory.
Expand All @@ -77,7 +77,7 @@ The following commands require a `nwb.config.js` file to be present to specify t
#### `serve` - serve an app

```
nwb serve
nwb serve [entry]
```

Starts a development server which serves an app with hot module reloading.
Expand All @@ -86,6 +86,8 @@ Starts a development server which serves an app with hot module reloading.
* Syntax errors made while the development server is running will appear as an overlay in your browser.
* Rendering errors in React components will also appear as an overlay.

Passing an argument for `entry` allows you to customise the entry point for your React or web app.

**Flags:**

* `--auto-install` - automatically install missing npm dependencies and save them to your app's package.json, for convenience during initial development/prototyping
Expand Down Expand Up @@ -116,18 +118,18 @@ Having a demo which uses your component is also a great way to test it as you pr
#### `build` - create builds

```
nwb build
nwb build [entry] [dist_dir]
```

Builds the project.

**In React/web apps:**

A static build will be created in `dist/`, with `app.js` and `app.css` files plus any other resources used.

By default, separate `vendor.js` and `vendor.css` files will be built for any dependencies used from `node_modules/`.
Default behaviour:

By default, static builds are created in production mode. Code will be minified and have dead code elimination performed on it (for example to remove unreachable, or development-mode only, code).
* A static build will be created in `dist/`, with `app.js` and `app.css` files plus any other resources used.
* Separate `vendor.js` and `vendor.css` files will be built for any dependencies used from `node_modules/`.
* Static builds are created in production mode. Code will be minified and have dead code elimination performed on it (for example to remove unreachable, or development-mode only, code).

To create a development build, set the `NODE_ENV` environment variable to `'development'` when running the `build` command; nwb supports a cross-platform way of doing this, using [argv-set-env](https://github.com/kentcdodds/argv-set-env):

Expand All @@ -139,6 +141,8 @@ nwb build --set-env-NODE_ENV=development
NODE_ENV=development nwb build
```

Passing arguments for `entry` and `dist_dir` allows you to customise the entry point for your app and the directory it gets build into.

**In React apps only:**

In production mode builds, the Babel 5 [constant-elements](https://github.com/babel/babel.github.io/blob/862b43db93e48762671267034a50c30c00e433e2/docs/advanced/transformers/optimisation/react/constant-elements.md) and [inline-elements](https://github.com/babel/babel.github.io/blob/862b43db93e48762671267034a50c30c00e433e2/docs/advanced/transformers/optimisation/react/inline-elements.md) React optimisation transforms will be used.
Expand All @@ -153,14 +157,18 @@ Builds the component in preparation for publishing to npm.

If the module has a `demo/` directory, running `build` will also create a static build of its demo app in `demo/dist/`.

Passing an argument for `entry` allows you to customise the entry point for the UMD build of your app.

#### `clean` - clean up

```
nwb clean
nwb clean [dist_dir]
```

Deletes all built resource directories.

For React and web apps, passing an argument for `dist_dir` allows you to customise the output directory which will be deleted.

### Project commands

The following commands don't require an `nwb.config.js` file to specify a project type, but it may be required for other configuration depending on the command.
Expand All @@ -182,19 +190,30 @@ Runs unit tests.

Running the test server in tandem with a hot reloading demo app, you can quickly protoype and test your components.

#### Project Type-specific Commands
#### Project-type-specific Commands

Project type-specific versions of the generic `build`, `clean` and `serve` commands are also available to run directly - if you use the generic commands, you will see nwb calling these for you:
Project-type-specific versions of the generic `build`, `clean` and `serve` commands are also available to run directly - if you use the generic commands, you will see nwb calling these for you:

* `build-demo` - build a demo app from `demo/src/index.js` to `demo/dist/`

* `build-module` - create an ES5 build for an npm module
* `build-react-app` - build a react app from `src/index.js` to `dist/`
* `build-umd` - create a UMD build for an npm module (this command itself requires configuration, so is useless without a config file)
* `build-web-app` - build a web app from `src/index.js` to `dist/`
* `clean-app` - delete `dist/`

* `build-react-app [entry] [dist_dir]` - build a react app from `entry` (default: `src/index.js`) to `dist_dir` (default: `dist/`)

* `build-umd [entry]` - create a UMD build for an npm module starting from `entry` (default: `src/index.js`) (this command requires configuration)

* `build-web-app [entry] [dist_dir]` - build a web app from `entry` (default: `src/index.js`) to `dist_dir` (default: `dist/`)

* `clean-app [dist_dir]` - delete `dist_dir` (default: `dist/`)

* `clean-demo` - delete `demo/dist/`

* `clean-module` - delete `coverage/`, `es6/` and `lib/

* `clean-umd` - delete `umd/`
* `serve-react-app` - serve a React app from `src/index.js`

* `serve-react-app [entry]` - serve a React app from `entry` (default: `src/index.js`)

* `serve-react-demo` - serve a React demo app from `demo/src/index.js`
* `serve-web-app` - serve a web app from `src/index.js`

* `serve-web-app [entry]` - serve a web app from `entry` (default: `src/index.js`)
1 change: 1 addition & 0 deletions docs/Middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Your app's version of the Express module must be passed as the first argument.
###### `options`

* `autoInstall` - automatically install missing npm dependencies. Default: `false`
* `entry` - entry point for the app. Default: `src/index.js`
* `info` - print info about Webpack modules after rebuilds. Default: `false`

#### Example
Expand Down
10 changes: 6 additions & 4 deletions express.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ module.exports = function(express, options) {
if (!options) options = {}

// Use options to create an object equivalent to CLI args parsed by minimist
var args = {}
args.info = !!options.info
args['auto-install'] = !!options.autoInstall
var args = {
_: ['serve-react-app', options.entry],
'auto-install': !!options.autoInstall,
info: !!options.info
}

var webpackConfig = createServerWebpackConfig(
args,
createServeReactAppBuildConfig(
createServeReactAppConfig()
createServeReactAppConfig(args)
)
)

Expand Down
Loading

0 comments on commit ae59a8c

Please sign in to comment.