Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Who optimizes the Javascript source code?

ANSWERED

I wrote below codes:

// app/mymodule.ts
const a = 0;

let unuseVariable = 1;
const unuseConst = 2;

export const c = a;

export class UnuseClass {
    someMethod() {
        return unuseConst
    }
}
// app/index.ts

import {c} from "./mymodule"

console.log(c);

 

Then I ran `npx tsc app / index.ts`. The following source code was generated.

//mymodule.js
"use strict";
exports.__esModule = true;
exports.UnuseClass = exports.c = void 0;
var a = 0;
var unuseVariable = 1;
var unuseConst = 2;
exports.c = a;
var UnuseClass = /** @class */ (function () {
    function UnuseClass() {
    }
    UnuseClass.prototype.someMethod = function () {
        return unuseConst;
    };
    return UnuseClass;
}());
exports.UnuseClass = UnuseClass;
//index.js
"use strict";
exports.__esModule = true;
var mymodule_1 = require("./mymodule");
console.log(mymodule_1.c);

 

Next, I run `npm run build`. The `index.js` included in` app.fba` is below.

"use strict"
console.log(0)

Unlike in `tsc`, unuse variables and class are deleted. And constant have been converted to literal.

Source codes are optimized!

 

This optimization is nice to me. But I have some questions.

  • Who is doing this? (inside of `fitbit-build` command?)
  • Can I rely this behavior without any setting? Is there any setting files to optimize?
Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

There's a lot going on in the build process which is handled by rollup.js. You can take a look at the tooling here https://github.com/Fitbit/fitbit-sdk-toolchain

View best answer in original post

Best Answer
2 REPLIES 2

There's a lot going on in the build process which is handled by rollup.js. You can take a look at the tooling here https://github.com/Fitbit/fitbit-sdk-toolchain

Best Answer

> JonFitbit

https://github.com/Fitbit/fitbit-sdk-toolchain

This is exactly the information I wanted! Thank you!

I wanted to know what was going on with 'fitbit-build'. I can be understand it by looking at this.

 

As a side note, I found out that `tsc` does not perform any optimization. Only perform the conversion.

Best Answer
0 Votes