-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* uglify-json * throw on error * Clean up JSONAsset Don’t extend from JSAsset
- Loading branch information
1 parent
a852dd2
commit c858843
Showing
3 changed files
with
34 additions
and
8 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,14 +1,28 @@ | ||
const JSAsset = require('./JSAsset'); | ||
const Asset = require('../Asset'); | ||
const {minify} = require('uglify-es'); | ||
|
||
class JSONAsset extends JSAsset { | ||
async load() { | ||
return 'module.exports = ' + (await super.load()) + ';'; | ||
class JSONAsset extends Asset { | ||
constructor(name, pkg, options) { | ||
super(name, pkg, options); | ||
this.type = 'js'; | ||
} | ||
|
||
parse() {} | ||
collectDependencies() {} | ||
pretransform() {} | ||
transform() {} | ||
generate() { | ||
let code = `module.exports = ${this.contents};`; | ||
|
||
if (this.options.minify) { | ||
let minified = minify(code); | ||
if (minified.error) { | ||
throw minified.error; | ||
} | ||
|
||
code = minified.code; | ||
} | ||
|
||
return { | ||
js: code | ||
}; | ||
} | ||
} | ||
|
||
module.exports = JSONAsset; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"test": "test" | ||
} |
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