Skip to content

Commit ef4e241

Browse files
author
benholloway
committed
update docs, fix dependency name
1 parent 97e4c42 commit ef4e241

File tree

3 files changed

+109
-51
lines changed

3 files changed

+109
-51
lines changed

config/add/common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ function common(loaderRoot, options) {
9191
test : /\.js$/i,
9292
include: /[\\\/]bower_components[\\\/]/i,
9393
loaders: [
94-
'sourcemap-sources?format=outputRelative',
94+
'adjust-sourcemap?format=outputRelative',
9595
'ng-annotate?sourceMap'
9696
]
9797
})
9898
.loader('js', {
9999
test : /\.js$/i,
100100
exclude: /[\\\/](bower_components|webpack|css-loader)[\\\/]/i,
101101
loaders: [
102-
'sourcemap-sources?format=projectRelative',
102+
'adjust-sourcemap?format=projectRelative',
103103
'ng-annotate?sourceMap',
104-
'sourcemap-sources?format=absolute', // fix ng-annotate source maps in Windows but tweaking incoming map
104+
'adjust-sourcemap?format=absolute', // fix ng-annotate source maps in Windows but tweaking incoming map
105105
'nginject?sourceMap&deprecate&singleQuote',
106106
'babel?sourceMap&ignore=buffer&compact=false'
107107
// https://github.com/feross/buffer/issues/79

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-angularity-solution",
3-
"version": "0.7.1",
3+
"version": "0.8.1",
44
"description": "Requisite configuration and modules to build Angularity projects with Webpack",
55
"main": "index.js",
66
"repository": {

readme.md

Lines changed: 105 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ The solution contained in this project with work with **NodeJS 4.0.0**. It is mo
1818

1919
* This package is **not** a global installation. You need to install as a [development dependency](https://docs.npmjs.com/files/package.json#devdependencies) in every single project you wish to build.
2020

21-
* This package does **not** contain [Karma](http://karma-runner.github.io/) and does not support Unit Testing without other pre-requisites (see below).
21+
* This package does **not** contain [Karma](http://karma-runner.github.io/) and does not support Unit Testing without other co-requisites (see below).
2222

23-
* This package does **not** contain the [Webpack CLI](https://github.com/webpack/docs/wiki/cli), you will need to install separately (see below).
23+
* This package presumes [npm scripts](https://docs.npmjs.com/misc/scripts). If you want to run outside of scripts you will need some additional global installs (see below).
2424

2525
## Installation
2626

@@ -47,23 +47,14 @@ npm install --save-dev webpack-angularity-solution
4747

4848
### Co-requisites
4949

50-
* Install [Webpack CLI](https://github.com/webpack/docs/wiki/cli) as a **global** package using NPM.
50+
Install [karma-angularity-solution](https://github.com/angularity/karma-angularity-solution) as a **local dev-dependency** if you expect to be running Unit Tests.
5151

52-
```
53-
npm install -g webpack
54-
```
55-
56-
* Install [cross-env](https://www.npmjs.com/package/cross-env) as a **global** package using NPM, to allow you to write environment variables from your [NPM scripts](https://docs.npmjs.com/misc/scripts).
57-
58-
```
59-
npm install -g cross-env
60-
```
52+
```
53+
npm install --save-dev karma-angularity-solution
54+
```
6155

62-
* Install [karma-angularity-solution](https://github.com/angularity/karma-angularity-solution) as a **local dev-dependency** if you expect to be running Unit Tests.
56+
Note that you do **not** need any global installs if you only use [npm scripts](https://docs.npmjs.com/misc/scripts). But if you operate outside of npm scripts you will find that you are missing [Webpack CLI](https://github.com/webpack/docs/wiki/cli), and [cross-env](https://www.npmjs.com/package/cross-env) as global installs.
6357

64-
```
65-
npm install --save-dev karma-angularity-solution
66-
```
6758

6859
### Each project
6960

@@ -74,56 +65,82 @@ Please read in full. Failure to configure any one of the following may leave you
7465
Use the following dev-dependencies and scripts in your project.
7566

7667
```json
77-
"scripts": {
78-
"build": "webpack -d --progress",
79-
"build-unminified": "cross-env MYPROJECT_NO_MINIFY=true webpack -d --progress",
80-
"watch": "webpack -d --watch",
81-
"watch-unminified": "cross-env MYPROJECT_NO_MINIFY=true webpack -d --watch",
82-
"release": "cross-env MYPROJECT_RELEASE=true npm run build"
83-
},
84-
"devDependencies": {
85-
"babel-plugin-add-module-exports": "^0.1.1",
86-
"babel-preset-es2015": "^6.3.13",
87-
"webpack-angularity-solution": "latest"
68+
{
69+
"scripts": {
70+
"build": "webpack -d --progress",
71+
"build-unminified": "cross-env UNMINIFIED=true webpack -d --progress",
72+
"watch": "webpack -d --watch",
73+
"watch-unminified": "cross-env UNMINIFIED=true webpack -d --watch",
74+
"release": "cross-env MODE=release webpack -d --progress"
75+
},
76+
"devDependencies": {
77+
"webpack-angularity-solution": "latest",
78+
"babel-plugin-add-module-exports": "^0.1.1",
79+
"babel-preset-es2015": "^6.3.13"
80+
}
8881
}
8982
```
9083

91-
You may be able to omit the babel dependencies if you have not been writing ES6 javascript.
84+
Some explanation:
9285

93-
Also don't forget to change **`MYPROJECT`** prefix to the name of your project to avoid environment variable crosstalk.
86+
* **BabelJS**
9487

95-
#### `webpack.conf.js`
88+
You may be able to omit the [BabelJS](https://babeljs.io/) dependencies if you have not been writing ES6 javascript.
89+
90+
* **cross-env**
91+
92+
Any setting passed to `cross-env` corresponds to environment variables. By convention they are `UPPERCASE`. These environment variables are private to the executable that follows so you don't need to worry about name conflicts across different projects.
93+
94+
#### `webpack.config.js`
9695

9796
Create a Webpack configuration file that delegates to the `webpack-angularity-solution` package. Use options taken from the same environment variables used in your `package.json` scripts.
9897

9998
```javascript
10099
/* global process:true */
101100

102-
module.exports = require('webpack-angularity-solution')({
103-
port : process.env.MYPROJECT_PORT ? parseInt(process.env.MYPROJECT_PORT) : undefined,
104-
noApp : process.env.MYPROJECT_NO_APP,
105-
noTest : process.env.MYPROJECT_NO_TEST,
106-
noMinify: process.env.MYPROJECT_NO_MINIFY,
107-
release : process.env.MYPROJECT_RELEASE,
108-
provide : {
101+
var angularity = require('webpack-angularity-solution');
102+
103+
module.exports = angularity(process.env, {
104+
globals: {
109105
$ : 'jquery',
110106
jQuery : 'jquery',
111107
'window.jQuery': 'jquery'
112108
}
109+
}).resolve(function () {
110+
/* jshint validthis:true */
111+
return (process.env.MODE in this) ? this[process.env.MODE] : [].concat(this.app).concat(this.test);
113112
});
114113
```
115114

116-
Note that there are **no globals** in applications bundled by Webpack. If your code relies on globals such as jQuery, you will have to configure the `provide` option as shown above. Add additional globals as required by your application.
115+
Some explanation:
116+
117+
* **Options by `process.env`**
118+
119+
In the example you can see that more than one configuration may be passed to `angularity()`. This means `process.env` may be passed in entirety.
120+
121+
Angularity will automatically convert any upper-case option `SOME_OPTION` to camel-case `someOption` and parse strings to the correct type.
122+
123+
* **Option `globals`**
124+
125+
Note that there are **no globals** in applications bundled by Webpack. If your code relies on globals such as jQuery, you will have to configure the `globals` option as shown above.
126+
127+
Add additional globals as required by your application.
128+
129+
* **The `resolve()` method**
130+
131+
This is pro-forma. Refer to the section on **extensability** for more detail.
132+
133+
Suffice to say that valid values of the `MODE` are `app`|`test`|`release`. Omission of `MODE` implies both `app` and `test` compilations.
117134

118135
#### `.babelrc`
119136

120-
If you are **compiling future Javascript** down to to current javascript you will need to configure **BabelJS** with the particulars.
137+
If you are **compiling future Javascript** down to to current javascript you will need to configure [BabelJS](https://babeljs.io/) with the particulars.
121138

122-
Angularity has traditionally supported ES6 (now es2015) so we will use that as an example. Also note that the Babel `default export` behaviour has changed so we will be use [babel-plugin-add-module-exports](https://www.npmjs.com/package/babel-plugin-add-module-exports) to retain the previous syntax.
139+
Angularity has traditionally supported ES6 (now es2015) so we will use that as an example. Also note that the Babel `default export` behaviour has changed so we will be use [babel-plugin-add-module-exports](https://www.npmjs.com/package/babel-plugin-add-module-exports) so that `require()` statements yeild the default export.
123140

124141
Both of these aspects were installed above as `devDependencies` so we can now create a babel-js [configuration file](https://babeljs.io/docs/usage/babelrc/) that uses them.
125142

126-
```
143+
```json
127144
{
128145
"presets": [
129146
"es2015"
@@ -144,16 +161,57 @@ For example:
144161

145162
* run a watch using `npm run watch`
146163

164+
* run release build using `npm run release`
165+
147166
### Options
167+
168+
#### General settings
169+
170+
```javascript
171+
port : 55555, // port to serve during watch
172+
unminified: false, // switch to unminified
173+
publicPath: undefined, // CDN path for release builds
174+
globals : {} // A hash of packages keyed by their global variable
175+
```
176+
177+
Note that if you have an `angularity.json` file then its `port` property will be used as the default value, rather than `55555`.
178+
179+
#### Full customisation
180+
181+
These settings deviate from the Angularity standard project structure
182+
183+
```javascript
184+
appDir : './app', // your composition roots
185+
buildDir : './app-build', // output of the app build
186+
testDir : './app-test', // output of the test build
187+
releaseDir: './app-release', // output of the release build
188+
testGlob : '**/*.spec.js' // identify your test files
189+
```
190+
191+
## Extensability
192+
193+
The result of `angularity()` is an instance with a number of accessors: `app`, `test`, `release`. Each accessor returns a [`webpack-configurator`](https://www.npmjs.com/package/webpack-configurator) or Array thereof.
194+
195+
The `webpack-configurator` instance(s) provide methods for extensibility of the configuration but is not a webpack configuration until `configurator.resolve()` is called. This is done automatically by the `angularity.resolve()` method, negating the need to iterate over the configurator instance(s).
196+
197+
```javascript
198+
module.exports = angularity(...)
199+
.resolve(function() {
200+
// this === angularity instance (i.e. this.app | this.test | this.release)
201+
// return a webpack-configurator or Array.<webpack-configurator>
202+
});
203+
```
204+
205+
Accessors:
148206

149-
* `port:int` Optional port (that overrides `angularity.json`)
207+
* **`instance.app : Array.<WebpackConfigurator>`**
150208

151-
* `noApp:boolean` Inhibit building the Application (speeds up the test build)
209+
Retrieve a list of webpack-configurator instances, one for each application in the `appDir`.
152210

153-
* `noTest:boolean` Inhibit building Unit Tests (speeds up the application build)
211+
* **`instance.test : WebpackConfigurator`**
154212

155-
* `noMinify:boolean` Inhibit minification of the application (test build is not minified)
213+
Retrieve a single webpack-configurator instance for unit tests.
156214

157-
* `release:boolean` Externalise the Webpack chunk manifest to allow long-term caching (incompatible with test build)
215+
* **`instance.release : WebpackConfigurator`**
158216

159-
* `provide:object` A hash of packages keyed by the global variable that they represent
217+
Retrieve a single webpack-configurator instance to release the root application in the `appDir`.

0 commit comments

Comments
 (0)