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
Upgrade build deps (Babel 7, bump webpack minor) #2036
Conversation
4d132a1
to
a573af6
Compare
8470a6b
to
3139c0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really for returning to Babel. Not sure what others think.
3k size decrease doesn't really convince me much honestly. If we chose to go for a language like Typescript I think it's better to stick with the original compiler by default. I don't see enough good strong points of Babel yet. What do you think @tjenkinson ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tchakabam - looks like the file size difference is -23k assuming if @johnBartos has accurate values in the PR description 😄Which is great if that's the case.
I'm fine with whatever build tooling we use that makes sense and results in the best bundle we can release with (smaller the better).
That being said, after reading the blog post you linked, I'm worried that we're now losing the ability to do type checking as mentioned in the Caveats
section:
As we mentioned above, the first thing users should be aware of is that Babel won’t perform type-checking on TypeScript code; it will only be transforming your code, and it will compile regardless of whether type errors are present. While that means Babel is free from doing things like reading .d.ts files and ensuring your types are compatible, presumably you’ll want some tool to do that, and so you’ll still need TypeScript. This can be done as a separate tsc --watch task in the background, or it can be part of a lint/CI step in your build. Luckily, with the right editor support, you’ll be able to spot most errors before you even save.
While our editors may or may not have TypeScript support so we can catch type errors during dev, there should still be a final step at the project level to do type checks.
@tchakabam @johnBartos perhaps we can find a middle ground here by adding the suggested background task mentioned in the above blog post quote^
@tchakabam 24k, not 3k. That's ~10% of the build size. I think there needs to be strong reasons not to use Babel, rather than using TSC.
Good idea! I can look into integrating tsc or linting. I'm leaning towards during the lint step because there's almost no ts today, and no PRs have been made with ts, so it's not efficient to always compile it |
Yeah that's true, although I thought there was a way to do only type checking (no compilation/emitting) with Perhaps |
Sorry misread that obviously :) 👍 That is definitely a good reason ✅ But unfortunately that doesn't resolve some questions I have. I'll try to develop a bit on it.
Unfortunately I can't necessarily agree with that idea. I don't find it as clearly logical as you seem to. First of all TSC is the default compiler for the TypeScript language which actually defines and implements the language-specs, it is like the defacto standard. It doesn't do minification/optimization, but it does also compile ES5+ code to ES5 and ES3. All the module bundling and optimization is imo better done further down the toolchain by chaining things via Webpack. Babel is another compiler that now added TS support on top of it's existing support of all sorts of JavaScript features, standardized or maybe-one-day standardized, and which main purpose arised from polyfilling these modern features as they were still missing native runtime support on many platforms. Typescript however is a whole own language that is however extremely compatible with JS. Think of it a bit like C and C++ maybe. However, unlike Babel, the compiler only compiles, but never fills in any actual missing runtime libraries or native objects. That is something however Babel may still do within a TypeScript toolchain setup in order to inject certain syntax-transforms or runtime-polyfills for specific build configurations (like IE11, if we'll ever want to use modern JS features like Promises). Now Babel can and will have features of the TypeScript language implemented later or potentially differing from the default i.e specified behavior. That is simply because unlike Babel, TSC gets developed inline by the actual specifying org of the Typescript language. Also, in Babel the error codes and compiler output will be different than what the current vast majority of the TS community is getting. Conclusion: Compiling TS with Babel is imo experimental. The reason why I say this is simply that I am now writing a lot of Typescript, and I have been since the last 2 years, and that also implied using TSC and not Babel. Which is the case for pretty much the whole TS community I think. Now, maybe one could also compile the TSC output with Babel (the individual modules) to leverage this binary size optimizations. Webpack can actually chain several loaders together. What I would for example need to get convinced of is that Babel implements TypeScript support in full fledge, and also provides proper error messages. But there are actually many open questions. What is the correspondance of Believe me I don't want to categorically push back on this, my concerns are objective and related to the good of the project. I see the size decrease is important and a strong point. I would just like to have good confidence about the support of TS in Babel beforehand, and also it being well-understood how the TSC behavior and config maps to Babel. TLDR: I believe that definitely Babel can be used for optimizing size and eventually allowing runtime compatibility or adding polyfills (if we ever want to use that), but we can actually combine it with TSC. We should use TSC to compile TS to ES5, and then run Babel on all these output JS modules + existing plain JS modules. That is a setup that can easily be achieved by chaining the loaders in webpack. |
I'd like to understand one thing about Quoting from a MS blog post on the Babel support:
from https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/ Let's try to get those 10% bin size gain while not running into issues with TS on the other side :) |
@itsjamie Any opinion on using TSC as a build step, but using Babel to emit the bundle? |
I think whichever results in a smaller build would be ideal, so Babel looks good to me 💯. Only caveat: We would have to limit what we wrote to things that Took a look over the community from Babel users who use typescript. General approach seems to be right in line here. If we add a npm task to run type-checking through
Which is invoked in CI, and could be run locally. Looks fine to me. Like @michaelcunningham19 called out, |
Also, VSCode will still run type-checking as you type so long as we leave the .tsconfig file alone, and add the |
"mocha": "^3.0.2", | ||
"selenium-webdriver": "^3.1.0", | ||
"should": "^13.1.3", | ||
"sinon": "^4.1.3", | ||
"ts-loader": "^4.4.2", | ||
"ts-node": "^6.1.0", | ||
"typescript": "^2.9.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should still install the typescript module so we can lock tsc
to a specific version and have access to a project local tsc
.
{ test: /\.ts?$/, loader: "ts-loader" }, | ||
{ test: /\.js?$/, exclude: [/node_modules/], loader: "ts-loader" }, | ||
{ | ||
test: /\.js$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also match .ts
?
entry: './src/hls', | ||
resolve: { | ||
// Add `.ts` as a resolvable extension. | ||
extensions: [".ts", ".js"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the project still build without extensions
including the ts extension? This was needed so the imports tested that file extension.
modules: false, | ||
targets: { | ||
browsers: [ | ||
'chrome >= 55', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think hls.js should target older chromium based browsers
For example, Tizen 2.3 TVs (which still have a large market share) ship with a webkit-based browser that corresponds chrome 22
https://developer.samsung.com/tv/develop/specifications/web-engine-specifications
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a good default would be M47 (>= 47), so we for sure support 2017 models.
I'll run a test with this and report back what happens if we drop the target to chrome 22 for the bundle size.
If it's a huge difference it may make sense to make a new target for very old browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As such the bundle size also stays the same with any of the provided targets.
plugins: [ | ||
{ | ||
visitor: { | ||
CallExpression: function (espath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why aren't you using babel-polyfill for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained to me, it's like a scalpel approach, we don't want to include a full polyfill that makes the environment completely ES2015 compliant, if we only use the single ES2015 feature. So the small change ends up being net better.
This PR will...
@babel/preset-typescript
instead ofts-loader
bundle-analyzer
optionwebpack-webworkify
number-isFinite
polyfillWhy is this Pull Request needed?
webpack-webworkify
supports webpack 4 only on the master branch. Unfortunately, the project looks pretty dead - I doubt it will be released. I forked it and fixed our version to its master branch.Number
- it always exists in the worker contextSize diff: 224k vs 247k!
Are there any points in the code the reviewer needs to double check?
No
Resolves issues:
Chore
Checklist