This repository was archived by the owner on Feb 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update deps * fix capitalization & grammar * update code * update tests * run on latest nodes * use exact versions * add link to api * use uglify-es * add modern js test * link to harmony * add credits * Delete CHANGELOG.md * Update .travis.yml * Clean up dotfiles * Update README.md * Update test.js * Update index.js * Update package.json * Update package.json * Code tweak
- Loading branch information
1 parent
8c67a01
commit c0e84b2
Showing
8 changed files
with
149 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
*~ | ||
*.bak | ||
.DS_Store | ||
npm-debug.log | ||
npm-debug.log* | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
*~ | ||
*.bak | ||
.DS_Store | ||
npm-debug.log | ||
.travis.yml | ||
test.js | ||
CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- 'node' | ||
- '5' | ||
- '4' | ||
- node | ||
- 8 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,51 @@ | ||
'use strict'; | ||
const {minify} = require('terser'); | ||
const anymatch = require('anymatch'); | ||
|
||
const uglify = require('uglify-js'); | ||
|
||
const formatError = (error) => { | ||
const err = new Error(`L${error.line}:${error.col} ${error.message}`); | ||
err.name = ''; | ||
err.stack = error.stack; | ||
const formatError = err => { | ||
err.message = `L${err.line}:${err.col} ${err.message}`; | ||
return err; | ||
}; | ||
|
||
class UglifyJSOptimizer { | ||
class TerserOptimizer { | ||
constructor(config) { | ||
this.options = Object.assign({}, config.plugins.uglify); | ||
this.options.fromString = true; | ||
this.options.sourceMaps = !!config.sourceMaps; | ||
const {ignored, ...options} = config.plugins.terser || {}; | ||
|
||
this.isIgnored = anymatch(ignored); | ||
this.options = { | ||
sourceMap: !!config.sourceMaps, | ||
...options, | ||
}; | ||
} | ||
|
||
optimize(file) { | ||
const data = file.data; | ||
const path = file.path; | ||
|
||
try { | ||
if (this.options.ignored && this.options.ignored.test(file.path)) { | ||
// ignored file path: return non minified | ||
const result = { | ||
data, | ||
// brunch passes in a SourceMapGenerator object, but wants a string back. | ||
map: file.map ? file.map.toString() : null, | ||
}; | ||
return Promise.resolve(result); | ||
} | ||
} catch (e) { | ||
return Promise.reject(`error checking ignored files to uglify ${e}`); | ||
if (this.isIgnored(file.path)) { | ||
return { | ||
data: file.data, | ||
map: file.map && `${file.map}`, | ||
}; | ||
} | ||
|
||
const options = {...this.options}; | ||
if (file.map) { | ||
this.options.inSourceMap = file.map.toJSON(); | ||
options.sourceMap = { | ||
content: JSON.stringify(file.map), | ||
url: `${file.path}.map`, | ||
}; | ||
} | ||
|
||
this.options.outSourceMap = this.options.sourceMaps ? | ||
`${path}.map` : undefined; | ||
const res = minify(file.data, options); | ||
if (res.error) throw formatError(res.error); | ||
if (!res.map) return {data: res.code}; | ||
|
||
try { | ||
const optimized = uglify.minify(data, this.options); | ||
|
||
const result = optimized && this.options.sourceMaps ? { | ||
data: optimized.code, | ||
map: optimized.map, | ||
} : { | ||
data: optimized.code, | ||
}; | ||
result.data = result.data.replace(/\n\/\/# sourceMappingURL=\S+$/, ''); | ||
|
||
return Promise.resolve(result); | ||
} catch (err) { | ||
return Promise.reject(formatError(err)); | ||
} | ||
return { | ||
data: res.code.replace(/\/\/# sourceMappingURL=\S+$/, ''), | ||
map: res.map, | ||
}; | ||
} | ||
} | ||
|
||
UglifyJSOptimizer.prototype.brunchPlugin = true; | ||
UglifyJSOptimizer.prototype.type = 'javascript'; | ||
TerserOptimizer.prototype.brunchPlugin = true; | ||
TerserOptimizer.prototype.type = 'javascript'; | ||
|
||
module.exports = UglifyJSOptimizer; | ||
module.exports = TerserOptimizer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
{ | ||
"name": "uglify-js-brunch", | ||
"version": "2.10.0", | ||
"description": "Adds Uglify minifying support to brunch.", | ||
"author": "Paul Miller (http://paulmillr.com/)", | ||
"homepage": "https://github.com/brunch/uglify-js-brunch", | ||
"keywords": ["brunchplugin", "uglify", "uglify-js", "optimizer"], | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:brunch/uglify-js-brunch.git" | ||
}, | ||
"version": "3.0.0", | ||
"description": "Adds Terser mangler/compressor support to Brunch", | ||
"keywords": [ | ||
"brunch-plugin", | ||
"terser", | ||
"uglify", | ||
"minifier", | ||
"optimizer" | ||
], | ||
"homepage": "https://github.com/brunch/terser-brunch", | ||
"bugs": "https://github.com/brunch/terser-brunch/issues", | ||
"license": "MIT", | ||
"author": "Paul Miller (http://paulmillr.com)", | ||
"repository": "brunch/terser-brunch", | ||
"scripts": { | ||
"test": "eslint index.js && mocha" | ||
"test": "mocha -r chai/register-should test" | ||
}, | ||
"dependencies": { | ||
"uglify-js": "~2.6.1" | ||
"terser": "^3", | ||
"anymatch": "^2" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.9.0", | ||
"eslint": "^3.12.2", | ||
"eslint-config-brunch": "^1", | ||
"mocha": "~1.17.1" | ||
"chai": "^4", | ||
"mocha": "^6" | ||
}, | ||
"eslintConfig": { | ||
"extends": "brunch" | ||
"peerDependencies": { | ||
"brunch": "^2" | ||
} | ||
} |
Oops, something went wrong.