Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] BundleBuilder: support modules using ES6 with usePredefineCalls #67

Merged
merged 1 commit into from
Aug 4, 2018
Merged
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
61 changes: 21 additions & 40 deletions lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const uglify = require("uglify-es");
const {pd} = require("pretty-data");
const esprima = require("esprima");
const escodegen = require("escodegen");
const {Syntax} = esprima;
// const MOZ_SourceMap = require("source-map");

Expand Down Expand Up @@ -321,46 +322,25 @@ class BundleBuilder {

compressJS(fileContent, resource) {
if ( this.optimize ) {
if ( typeof fileContent === "object" && fileContent.type in Syntax ) {
let uglifyAST = uglify.AST_Node.from_mozilla_ast(fileContent);
let result = uglify.minify(uglifyAST, {
warnings: false, // TODO configure?
compress: false, // TODO configure?
output: {
comments: copyrightCommentsPattern
}
// , outFileName: resource.name
// , outSourceMap: true
});
if ( result.error ) {
throw result.error;
let result = uglify.minify({
[resource.name]: String(fileContent)
}, {
warnings: false, // TODO configure?
compress: false, // TODO configure?
output: {
comments: copyrightCommentsPattern
}
// console.log(result.map);
// const map = new MOZ_SourceMap.SourceMapConsumer(result.map);
// map.eachMapping(function (m) { console.log(m); }); // console.log(map);
fileContent = result.code;
// throw new Error();
} else {
let result = uglify.minify({
[resource.name]: String(fileContent)
}, {
warnings: false, // TODO configure?
compress: false, // TODO configure?
output: {
comments: copyrightCommentsPattern
}
// , outFileName: resource.name
// , outSourceMap: true
});
if ( result.error ) {
throw result.error;
}
// console.log(result.map);
// const map = new MOZ_SourceMap.SourceMapConsumer(result.map);
// map.eachMapping(function (m) { console.log(m); }); // console.log(map);
fileContent = result.code;
// throw new Error();
// , outFileName: resource.name
// , outSourceMap: true
});
if ( result.error ) {
throw result.error;
}
// console.log(result.map);
// const map = new MOZ_SourceMap.SourceMapConsumer(result.map);
// map.eachMapping(function (m) { console.log(m); }); // console.log(map);
fileContent = result.code;
// throw new Error();
}
return fileContent;
}
Expand All @@ -382,14 +362,15 @@ class BundleBuilder {
let remaining = [];
for ( let module of sequence ) {
if ( /\.js$/.test(module) ) {
// console.log("trying to read " + module);
// console.log("Processing " + module);
let resource = await this.pool.findResourceWithInfo(module);
let code = await resource.buffer();
const ast = rewriteDefine(this.targetBundleFormat, code, module, avoidLazyParsing);
if ( ast ) {
outW.startSegment(module);
outW.ensureNewLine();
const fileContent = this.compressJS( ast, resource );
let astAsCode = escodegen.generate(ast);
const fileContent = this.compressJS(astAsCode, resource);
outW.write( fileContent );
outW.ensureNewLine();
const compressedSize = outW.endSegment();
Expand Down
88 changes: 42 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"@ui5/fs": "^0.2.0",
"@ui5/logger": "^0.2.0",
"archiver": "^2.1.0",
"escodegen": "^1.11.0",
"escope": "^3.6.0",
"esprima": "^2.7.2",
"estraverse": "^4.2.0",
Expand Down