Skip to content

Commit

Permalink
Merge pull request #1039 from stealjs/major
Browse files Browse the repository at this point in the history
Merge major -> master for steal-tools 2.0
  • Loading branch information
matthewp committed Jul 19, 2018
2 parents 38db05d + 3295d7a commit 1fe9f32
Show file tree
Hide file tree
Showing 149 changed files with 2,054 additions and 549 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -9,7 +9,6 @@ test/css_paths/bundles/
node_modules
!test/bundle_false/node_modules
!test/bundle_false_cdn/node_modules
bower_components
/packages/
test/out/
test/bundle/bundles/
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
@@ -1,12 +1,9 @@
language: node_js
node_js:
- 4
- 6.0
- 8.0
- node
- 10.2.1
before_script:
- npm install -g bower
- bower install
- npm dedupe
before_install:
- "export DISPLAY=:99.0"
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Expand Up @@ -10,7 +10,6 @@ install:
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
- npm run bower-install

# Post-install test scripts.
test_script:
Expand Down
8 changes: 0 additions & 8 deletions bower.json

This file was deleted.

34 changes: 17 additions & 17 deletions doc/transform.md
@@ -1,5 +1,5 @@
@function steal-tools.transform transform
@parent steal-tools.JS
@parent steal-tools.JS

A function provided by [steal-tools.transformImport] that returns a transformed
module or modules.
Expand All @@ -10,59 +10,59 @@ module or modules.

@param {steal-tools.transform.options} [options]

Options that configure how the files are compiled. These options overwrite the
Options that configure how the files are compiled. These options overwrite the
`pluginifierOptions` argument passed to [steal-tools.transformImport].

@return {steal-tools.source.object} An object containing a string `code` property and a `map` that is the source map if the `sourceMaps` option is set to `true`.
@return {Promise.<steal-tools.source.object>} A promise for an object containing a string `code` property and a `map` that is the source map if the `sourceMaps` option is set to `true`.

@body

## Use

After getting `transform` from [steal-tools.transformImport] you can call it, like:

var result = transform("module/name/to/build", {
var promise = transform("module/name/to/build", {
// specifies modules to ignore
ignore: [
// ignores this module, and all of its dependencies
"module/name/to/ignore",
// ignores modules with names matching this pattern
/can\//
],

// Remove code between !steal-remove-start and !steal-remove-end.
// true by default.
removeDevelopmentCode: true,

// Transpile the code to either "amd", "steal", "cjs" or "global".
// "global", the default, allows the file to work without any
// "global", the default, allows the file to work without any
// module loader.
format: "global",

// Minify the file using uglify.
// `false` by default.
minify: true,
// Only write the module specified by `moduleName`, instead of its

// Only write the module specified by `moduleName`, instead of its
// dependencies. `false` by default.
ignoreAllDependencies: false

// Map module names to their name on the global object. Useful for
// building "global" modules that depend on other scripts already in
// building "global" modules that depend on other scripts already in
// the page.
exports: {"jquery": "jQuery"},

// Transpile to normalized dependency names.
// `true` by default.
useNormalizedDependencies: true

// Custom normalization behavior
// By default, the normalized name is used.
normalize: function(name, currentModule, address){
return name;
}

});
Most of these options are optional. For more

Most of these options are optional. For more
information, read [steal-tools.transform.options transformOptions].
70 changes: 42 additions & 28 deletions doc/types/build-options.md
Expand Up @@ -3,7 +3,7 @@

Options used to configure the build process.

@option {Boolean|Function} [minify=true]
@option {Boolean|Function} [minify=true]

**Boolean**

Expand All @@ -24,7 +24,7 @@ A function can be provided to handle minification of each file in a bundle, e.g:
```javascript
stealTools.build(config, {
minify: function(source, options) {
// use your own library to minify source.code
// use your own library to minify source.code
source.code = doCustomMinification(source.code);

// return the source object when minification is complete
Expand Down Expand Up @@ -52,7 +52,7 @@ process; the second parameter, `options`, is the [steal-tools.BuildOptions] obje

@option {steal-tools.BundleAssetsOptions|Boolean} [bundleAssets=false] Set to true to have assets from your project bundled into your dest folder.

@option {Array.<moduleName>} ignore An array of module names that should be ignored and not included in the bundled file.
@option {Array.<moduleName>} ignore An array of module names that should be ignored and not included in the bundled file.
For more information take a look at the `ignore` usage http://stealjs.com/docs/steal-tools.build.html#ignore


Expand All @@ -62,13 +62,13 @@ for any `bundle` module. Defaults to `3`.
@option {Number} [maxMainRequests=3] The maximum number of bundles that will be loaded for any `main`
module. Defaults to `3`.

@option {Boolean} [removeDevelopmentCode=true] Remove any development code from the bundle specified
@option {Boolean} [removeDevelopmentCode=true] Remove any development code from the bundle specified
using `//!steal-remove-start`, and `//!steal-remove-end` comments.

@option {Object} [cleanCSSOptions] A hash of options to customize the minification of css files.
@option {Object} [cleanCSSOptions] A hash of options to customize the minification of css files.
All available options are listed in the [clean-css documentation](https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-programmatically).

@option {Object} [uglifyOptions] A hash of options to customize the minification of JavaScript files. StealTools uses the
@option {Object} [uglifyOptions] A hash of options to customize the minification of JavaScript files. StealTools uses the
top-level `minify` function of uglify-js, and the available options are listed [here](https://github.com/mishoo/UglifyJS2#minify-options).

For example, to not uglify function names you can use [keep_fnames option](https://github.com/mishoo/UglifyJS2#mangle-options):
Expand All @@ -89,24 +89,30 @@ stealTools.build(config, {

@option {Boolean} [watch=false] Actives watch mode which will continuously build as you develop your application.

@option {Boolean} [envify=false] Replace Node-style environment variables with plain strings.
@option {Boolean} [envify=true] Replace Node-style environment variables with plain strings.

steal-tools uses [loose-envify](https://github.com/zertosh/loose-envify) under the hood, this option is specially useful when building React.js applications.

Usage:

First, make sure `NODE_ENV` is set appropiately, then just turn on the envify option;
if you're using the steal-tools CLI modify your build command to look like:
First, make sure `NODE_ENV` is set appropiately; by default the build command will
turn `envify` on, just run:

```
NODE_ENV=production steal-tools build --envify
NODE_ENV=production steal-tools build
```

or, if you're using the build API just pass the option like this:
If you want to turn off this behavior, just pass the following flag to the CLI:

```
NODE_ENV=production steal-tools build --no-envify
```

or, set the flag to false when using the build API, like this:

```javascript
stealTools.build({}, {
envify: true
envify: false
});
```

Expand All @@ -127,7 +133,7 @@ like any other bundle.
Usage:

```js
stealTools.optimize({}, {
stealTools.optimize({}, {
target: "node"
});
```
Expand All @@ -137,7 +143,7 @@ Setting target to `node` makes the loader suitable to run on Node.js environment
Multiple targets can be set by passing an array of supported targets, e.g:

```js
stealTools.optimize({}, {
stealTools.optimize({}, {
target: ["node", "web"]
});
```
Expand All @@ -159,12 +165,12 @@ For example, a build targeting both node and web will look like the tree below:
@option {Boolean|String} [bundleManifest=false] Generates an HTTP2-push like manifest of the application bundles for server-side preload.

When set to `true` a `bundles.json` file will be written at the top level of the folder where the built assets are located (see the property`dest` above).
When set to `true` a `bundles.json` file will be written at the top level of the folder where the built assets are located (see the property`dest` above).

A full path to the desired JSON filename can be provided, too. e.g:

```js
stealTools.build(config, {
stealTools.build(config, {
bundleManifest: path.join(__dirname, "dist", "my-manifest.json")
});
```
Expand All @@ -188,37 +194,45 @@ The manifest has the following shape:

The top-level objects correspond to _entry level bundles_; these are the bundles needed to start up individual "pages" of the application and progressively loaded bundles.

The nested objects are _shared bundles_, these are created by `steal-tools` to minimize the number of HTTP requests needed to load the application code.
The nested objects are _shared bundles_, these are created by `steal-tools` to minimize the number of HTTP requests needed to load the application code.

Each _shared bundle_ has two properties, `type`, an string that indicates whether the bundle contains script code or styles and `weight`, a number indicating loading priority; a bundle with lower weight should be loaded before other bundles, e.g: style bundles have `weight` of `1` and should be loaded before script bundles.

@option {Boolean} [bundlePromisePolyfill=true] Bundles a Promise polyfill with StealJS core
@option {Boolean} [bundlePromisePolyfill=false] Bundles a Promise polyfill with StealJS core

By default, `steal-tools`'s output requires `Promises` being natively supported in the target environment where the application runs; if `Promises` [are not supported](https://caniuse.com/#feat=promises), turn on this flag to include the polyfill in your built code, e.g:

By default, [steal-tools.build] will add a Promise polyfill as part of the StealJS core. If Promises are supported natively in the target environment of your application
you can turn this flag off to prevent the polyfill to be included, like this:

```js
stealTools.build(config, {
bundlePromisePolyfill: false
bundlePromisePolyfill: true
});
```

steal-tools will write a file called `steal.sans-promises.production.js` to the bundles folder, make sure the script tag in your main html page loads the correct file, e.g:
`steal-tools` will write a file called `steal-with-promises.production.js` to the bundles folder, make sure the script tag in your main html page loads the correct file, like this:


```html
<script src="./dist/steal.sans-promises.production.js"></script>
<script src="./dist/bundles/steal-with-promises.production.js"></script>
```

The `bundlePromisePolyfill` also changes the default behavior of [bundleSteal], meaning that
the Promise polyfill will be excluded from StealJS core regardless of whether it is part of the main bundle or not.

To bundle StealJS without the Promise polyfill just pass the following options to [steal-tools.build]:
The `bundlePromisePolyfill` flag also changes the default behavior of the build command when `bundleSteal` is set; the Promise polyfill will be included in StealJS core regardless of whether StealJS's code is part of the main bundle or not.

To bundle StealJS with the Promise polyfill just pass the following options to [steal-tools.build]:

```js
stealTools.build(config, {
bundleSteal: true,
bundlePromisePolyfill: false
bundlePromisePolyfill: true
});
```

@option {Boolean} [treeShaking=true] Tree shakes the dependency graph, removing dead code created from unused exports. For more information on how tree shaking works, see the [steal-tools.tree-shaking] topic.

Tree shaking is enabled by default. Set this flag to false if you would like to disable it (this might be necessary in legacy applications that depend on side effects created by unused exports).

```js
stealTools.build(config, {
treeShaking: false
});
```
2 changes: 1 addition & 1 deletion doc/types/steal-config.md
Expand Up @@ -20,7 +20,7 @@ will also specify `baseURL`, and sometimes `main`. This sets [config.configPath]
@option {String} [baseURL] If a configuration file is not used,
the [config.baseURL baseURL] value must be set.

@option {Array<moduleName>} [bundle] An array of <moduleNames> that should be progressively loaded.
@option {Array<moduleName>} [bundle] An array of <moduleNames> that should be progressively loaded. See steal's [bundle](https://stealjs.com/docs/config.bundle.html) property for more information.

@option {Object<config.jsonOptions>} [jsonOptions] Provides options that can be applied to JSON loading.
Using the `transform` method will run through all JSON files while building, also the `package.json`'s of loaded modules
Expand Down
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -24,6 +24,7 @@ module.exports = {
.createBundleGraphStream,

transpile: require("./lib/stream/transpile"),
treeshake: require("./lib/stream/treeshake"),
minify: require("./lib/stream/minify"),
bundle: require("./lib/stream/bundle"),
concat: require("./lib/bundle/concat_stream"),
Expand Down
3 changes: 2 additions & 1 deletion lib/assign_default_options.js
Expand Up @@ -8,6 +8,7 @@ module.exports = function(config, options){
}

options = assign({ // Defaults
envify: true,
minify: false,
bundleSteal: false,
uglifyOptions: {},
Expand All @@ -17,7 +18,7 @@ module.exports = function(config, options){
},
removeDevelopmentCode: true,
namedDefines: true,
bundlePromisePolyfill: true,
bundlePromisePolyfill: false,
maxBundleRequests: options.maxBundleRequests || options.bundleDepth,
maxMainRequests: options.maxMainRequests || options.mainDepth
}, options);
Expand Down
54 changes: 28 additions & 26 deletions lib/build/export.js
Expand Up @@ -114,33 +114,35 @@ module.exports = function(config, defaults, modules){
ignore: outputOptions.ignore || out.output.ignore
});

var result = transform(moduleNames, options);
var filePath;

if (_.isUndefined(out.output.dest)) {
return Promise.reject(new Error(
"Attribute 'dest' is required\n" +
"Add 'dest' to the ExportOutput object.\n" +
"See http://stealjs.com/docs/steal-tools.export.output.html#dest for more details."
));
}
else if (_.isString(out.output.dest)) {
filePath = out.output.dest;
}
else if (_.isFunction(out.output.dest)) {
// pull out the load objects of the modules being written out
var loads = (_.isString(moduleNames) ?
transform.graph[moduleNames].load :
moduleNames.map(function(moduleName){
return transform.graph[moduleName].load;
}));

filePath = out.output.dest(moduleNames,
modulesMap[moduleNames], loads, transform.loader);
}
return transform(moduleNames, options)
.then(function(result){
var filePath;

if (_.isUndefined(out.output.dest)) {
return Promise.reject(new Error(
"Attribute 'dest' is required\n" +
"Add 'dest' to the ExportOutput object.\n" +
"See http://stealjs.com/docs/steal-tools.export.output.html#dest for more details."
));
}
else if (_.isString(out.output.dest)) {
filePath = out.output.dest;
}
else if (_.isFunction(out.output.dest)) {
// pull out the load objects of the modules being written out
var loads = (_.isString(moduleNames) ?
transform.graph[moduleNames].load :
moduleNames.map(function(moduleName){
return transform.graph[moduleName].load;
}));

filePath = out.output.dest(moduleNames,
modulesMap[moduleNames], loads, transform.loader);
}

winston.info("> " + filePath);
return writeFile(filePath, result, config);
winston.info("> " + filePath);
return writeFile(filePath, result, config);
});
};

var processOutput = function(transform, out) {
Expand Down

0 comments on commit 1fe9f32

Please sign in to comment.