I have a library that I need to use. It uses ES6 stuff.
It is not being processed by Traceur and I cannot figure out how to change that.
The libraries are being included into a normal component and accessed from there. IE,
import formatPlanPdf from “node_modules/format-plan-pdf/”;
Works fine in development. Kills minify on the production build because it doesn’t do ES6.
This is killing me. Please help.
Hey, sorry for not responding before. I don’t follow the problem exactly though. I think maybe you are saying that you need to transpile this module before minifying, is that correct?
Currently transpiling is only supported for ES modules (modules that use import/export). If you need to transpile it you’ll have to turn off minification and do transpiling yourself:
stealTools.build({
config: __dirname + "/package.json!npm"
}, {
minify: false
});
Then you can do use Babel and Uglify directly yourself:
> babel dist/bundles
> uglify dist/bundles/my/app.js > dist/bundles/my/app.js
Have the ability to transpile non-ES modules is on our roadmap though.
I guess I wasn’t clear. I do not have special needs.What I have is a module that is not a ‘component’. (It does a whole bunch of stuff that eventually loads a PDF into an iframe.)
The module is, however, imported into the app in the normal way…
import formatPlanPdf from "node_modules/format-plan-pdf/";
and the imported object ‘formatPlanPdf’ works perfectly well as long as I never use ES6 stuff.
I can use ES6 in all of my normal donejs modules (components, modules) but, in this special one, if I use ES6 it works fine on my dev system but when I deploy it, it fails at the minify step.
It never fails in the normal modules. Always fails for this special one and only when ES6 features, e.g., const {a, b}={a:‘a’, b:‘a’}, are used. I have done enough testing to be sure that this is the case.
I infer that, since Transpiling makes ES6 features pass minify when in normal modules, that the transpile step is not acting on my special module format-plan-pdf.js.
I have solved this problem. It was pretty obscure so I thought I would write this summary.
The problem is that I created a module that crashes the steal-tools build process. After endless investigation, I found that the problem occurred when the module contained ES6 features. If I revised the module to use strictly ES5 features, the crash did not occur. This, it turns out, was a red herring.
Working on a different problem, I ran into a page about configuration of steal metadata (here). On the page, it said this…
It turns out that my long-standing module pattern is exactly that, i.e., …
"use strict"
var constructor=function(args){
//blah blah
var tmp = function ( ) {/*code*/}; //sad old ES5 code
return this;
}
module.exports=constructor;
This works with steal-tools build process. However, if I add ES6 features, like this…
"use strict"
var constructor=function(args){
//blah blah
const tmp = ( ) => { /*code*/ }; //ES6 goodness
return this;
}
module.exports=constructor;
… it crashes steal-tools. (I note that it works perfectly fine in Dev when building is not an issue.)
Inspired by the metadata page, I changed it to this…
"use strict"
export default function(args){
//blah blah
const tmp = ( ) => { /*code*/ }; //ES6 goodness
return this;
}
… and steal-tools builds without error. Turns out it prefers ES6 import/export for transpiling.
1 Like
Now I understand this. I did not, when I read this, contemplate the difference between “module.exports” and “export default”. Obvious now.
Sorry I was dense. As you see above, I have finally gotten a clue.
1 Like