Skip to content

Commit 3ccb2bc

Browse files
author
benholloway
committed
placed preference to npm over Bower modules, fixed option nesting for environment variables, bump minor version
1 parent 7051a0c commit 3ccb2bc

File tree

5 files changed

+69
-38
lines changed

5 files changed

+69
-38
lines changed

config/add/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ function common(loaderRoot, options) {
3737
alias : {
3838
npm: path.resolve('node_modules')
3939
},
40-
root : path.resolve('bower_components'),
41-
fallback: path.resolve('node_modules')
40+
root : path.resolve('node_modules'),
41+
fallback: path.resolve('bower_components')
4242
},
4343
resolveLoader: {
4444
root : loaderRoot,

lib/default-options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22

3+
/**
4+
* The default options of the application.
5+
* @returns {object}
6+
*/
37
function defaultOptions() {
48
return {
59
appDir : './app',

lib/parse-options.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
var camelcase = require('camelcase'),
44
objectPath = require('object-path');
55

6+
/**
7+
* Parse the given options where keys may be in camel-case or as environment variable.
8+
* Nested fields are supported by dot-delimited camel-case, or double-underscore delimited uppercase
9+
* IEEE Std 1003.1-2001.
10+
* @param {object} options A hash of options
11+
* @param {object} defaults A hash of the default values of all valid options
12+
* @returns {object} A complete set, preferring options and using defaults otherwise
13+
*/
614
function parseOptions(options, defaults) {
715
return Object.keys(options)
816
.reduce(eachOptionKey, defaults);
917

1018
function eachOptionKey(reduced, key) {
1119
var expectedKey = key
12-
.split('.')
20+
.split('__')
1321
.map(eachElement)
1422
.join('.');
1523

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.10.0",
3+
"version": "0.11.0",
44
"description": "Requisite configuration and modules to build Angularity projects with Webpack",
55
"main": "index.js",
66
"repository": {

readme.md

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,28 @@ stats : { // console output
191191

192192
Note that if you have an `angularity.json` file then its `port` property will be used as the default value, rather than `55555`.
193193

194+
#### Environment variables
195+
196+
All options may be parsed from uppercase environment variables.
197+
198+
Use an underscrore to delimit camel-case, meaning `buildDir` is written as environment variable `BUILD_DIR`.
199+
200+
Use a double underscore to delimit a nested field, meaning `stats.warnings` is written as environment variable `STATS__WARNINGS`.
201+
202+
For example, to **suppress warnings** during the build:
203+
204+
```json
205+
{
206+
"scripts": {
207+
"silent": "cross-env STATS__WARNINGS=false webpack -d --progress"
208+
...
209+
}
210+
}
211+
```
212+
194213
#### Full customisation
195214

196-
These settings deviate from the Angularity standard project structure
215+
These additional settings may be used to deviate from Angularity's optinionated project structure.
197216

198217
```javascript
199218
appDir : './app', // your composition roots
@@ -203,20 +222,18 @@ releaseDir: './app-release', // output of the release build
203222
testGlob : '**/*.spec.js' // identify your test files
204223
```
205224

206-
#### Environment variables
225+
### Bower
207226

208-
All options may be parsed from uppercase environment variables. Use a dot to delimit depth.
227+
Bower packages may be imported like node modules but if there is a node module of the same name available then it will be used in preference.
209228

210-
For example, to **suppress warnings** during the build:
229+
Inline loader statements (see shimming) cannot be used when requiring bower packages. If the package requires globals (such as jQuery) then then need to be set in the Angularity options.
230+
231+
### Shimming
232+
233+
If a package does not export anything, or requires some global, then it may be [shimmed](https://github.com/webpack/docs/wiki/shimming-modules) on an as-used basis.
234+
235+
Since the **Angular** package does not export anything it would normally require the `export-loader?angular` statement to be used. However this is already taken care of in the common configuration and you do not need to take further action.
211236

212-
```json
213-
{
214-
"scripts": {
215-
"silent": "cross-env STATS.WARNINGS=false webpack -d --progress"
216-
...
217-
}
218-
}
219-
```
220237

221238
## Extensability
222239

@@ -238,22 +255,42 @@ The result of `angularity()` is an instance with a number of accessors - `app`,
238255

239256
### Resolving
240257

241-
While webpack-configurator provides methods for extensibility of the configuration it is not a valid 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).
258+
While [webpack-configurator](https://www.npmjs.com/package/webpack-configurator) provides methods for extensibility of the configuration it is not a valid webpack configuration until `configurator.resolve()` is called.
259+
260+
This is done automatically by the `angularity.resolve()` method, removing the need to iterate over the (possibly numerous) configurator instances.
242261

243262
```javascript
244263
module.exports = angularity(...)
245264
.resolve(function() {
246265
// this === angularity instance (i.e. this.app | this.test | this.release)
247266
// return a webpack-configurator or Array.<webpack-configurator>
248-
// the .resolve() method will be called on each element returned
267+
// the .resolve() method will be called on each element returned
249268
});
250269
```
251270

252271
### Operators
253272

254273
In order to create the configurators for each **mode**, a number of additional **operators** are added to `webpack-configurator`.
255274

256-
The default operators include:
275+
You may add your own operator using the `extend()` method. Each operator is called with the current instance of the Configurator as `this` and should return the same or a new Configurator.
276+
277+
For example, to add the `foo` operator:
278+
279+
```javascript
280+
module.exports = angularity(...)
281+
.extend({
282+
foo: function foo() {
283+
return this
284+
.merge({...}); // use the fluent webpack-configurator API
285+
}
286+
})
287+
.resolve(function () {
288+
return this.test
289+
.foo(); // operators are available on any Configurator instances comming out of 'test'
290+
})
291+
```
292+
293+
There are a number of operators used internally. These include:
257294

258295
* `addBrowserSync(directory:string, port:number):Configurator`
259296

@@ -285,22 +322,4 @@ The default operators include:
285322

286323
* `addTestSuiteGeneration(outputFile:string, testGlob:string):Configurator`
287324

288-
Locate all specification files and generate a file that require()s them all.
289-
290-
You may alter these operators or add your own using the `extend()` method.
291-
For example, if you want to re-implement the common configuration then override the `addCommon` operator:
292-
293-
```javascript
294-
var oldCommon = require('webpack-angularity-solution/config/add/common');
295-
296-
module.exports = angularity(...)
297-
.extend({
298-
addCommon: function(loaderRoot, options) {
299-
return oldCommon.call(this, loaderRoot, options)
300-
.merge({...})
301-
}
302-
})
303-
.resolve(function() {
304-
...
305-
});
306-
```
325+
Locate all specification files and generate a file that require()s them all.

0 commit comments

Comments
 (0)