Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Also works with `--fix` to automatically fix and report warnings as you work!
- `build` Added a CLI argument for setting the `basePath` option: `--base-path`.
- Derives node version check from the package.json.
- Added `js-ignore` option for skipping files in js minification process.

## v1.5.7 [10-11-2017]
- Updated css-slam, bower and other dependencies.
Expand Down
4 changes: 4 additions & 0 deletions custom_typings/matcher.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'matcher' {
import {matcher} from 'matcher';
export = matcher;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"gunzip-maybe": "^1.3.1",
"html-minifier": "^3.0.1",
"inquirer": "^1.0.2",
"matcher": "^1.0.0",
"merge-stream": "^1.0.1",
"mz": "^2.6.0",
"plylog": "^0.4.0",
Expand Down
28 changes: 26 additions & 2 deletions src/build/optimize-streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const externalHelpersPlugin = require('babel-plugin-external-helpers');
// entity. Upgrade to proper JS import once compatible .d.ts file is released,
// or consider writing a custom declaration in the `custom_typings/` folder.
import File = require('vinyl');
import matcher = require('matcher');

const logger = logging.getLogger('cli.build.optimize-streams');

Expand All @@ -40,7 +41,7 @@ export type CSSOptimizeOptions = {
export interface OptimizeOptions {
html?: {minify?: boolean};
css?: {minify?: boolean};
js?: {minify?: boolean, compile?: boolean};
js?: {minify?: boolean, compile?: boolean, ignore?: string[]};
}
;

Expand Down Expand Up @@ -77,6 +78,12 @@ export class GenericOptimizeTransform extends Transform {
return;
}

if (this.optimizerOptions.presets && this.optimizerOptions.presets[0].ignore === true) {
logger.warn('skip minify for ...' + file.path );
callback(null, file);
return;
}

if (file.contents) {
try {
let contents = file.contents.toString();
Expand Down Expand Up @@ -211,7 +218,24 @@ export function getOptimizeStreams(options?: OptimizeOptions):
/\.html$/, new InlineCSSOptimizeTransform({stripWhitespace: true})));
}
if (options.js && options.js.minify) {
streams.push(gulpif(/\.js$/, new JSDefaultMinifyTransform()));
if (options.js.ignore) {
const ignores = options.js.ignore;

function condition(file: File): boolean {
for (const ignore of ignores) {
if (matcher.isMatch(file.path, ignore) || file.basename === ignore) {
logger.warn('skipping minify for ' + file.path );
return false;
}
}

return /\.js$/.test(file.path);
}
streams.push(gulpif(condition, new JSDefaultMinifyTransform()));
}
else {
streams.push(gulpif(/\.js$/, new JSDefaultMinifyTransform()));
}
}

return streams;
Expand Down
9 changes: 9 additions & 0 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ export class BuildCommand implements Command {
description: 'Compile ES2015 JavaScript features down to ES5 for ' +
'older browsers.'
},
{
name: 'js-ignore',
type: Array,
description: 'When js-minify is `true`. allow to specify an array of string ' +
'for files that should be ignored (not minified).' +
'Specify either the exact file name or a wildcard expression (as in https://www.npmjs.com/package/matcher) ' +
'that will be matched against the full path.' +
'Example: { "minify": true ,"ignore": "*.min.js","firebase-database.js"}'
},
{
name: 'js-minify',
type: Boolean,
Expand Down
Loading