admin管理员组文章数量:1405516
I saw those javascript front-end build tools, e.g. webpack, using the word "pile" from time to time. I am not sure what does pile javascript codes mean exactly, at least not like pile c/c++ codes.
I think I understand the "build" process in general, like bundle all js codes into one big file, minify/uglify the codes, using babel to transforms ES6 syntax(transpile). But what does piling mean here, how does it fit in the whole building process or it is just another name for the whole build process?
Currently, I thought it may be just another name for using Babel to transforms ES6 syntax.
PS. after reading this SO Is Babel a piler or transpiler? I believe my question is not same as that. Because it is not just related to Bable. For example, webpack also uses the term piler / I do not understand its meaning there!
Browserify uses piler as well e.g, "Compiles underscore templates from HTML script tags into CommonJS in a browserify transform"
I saw those javascript front-end build tools, e.g. webpack, using the word "pile" from time to time. I am not sure what does pile javascript codes mean exactly, at least not like pile c/c++ codes.
I think I understand the "build" process in general, like bundle all js codes into one big file, minify/uglify the codes, using babel to transforms ES6 syntax(transpile). But what does piling mean here, how does it fit in the whole building process or it is just another name for the whole build process?
Currently, I thought it may be just another name for using Babel to transforms ES6 syntax.
PS. after reading this SO Is Babel a piler or transpiler? I believe my question is not same as that. Because it is not just related to Bable. For example, webpack also uses the term piler https://webpack.js/api/piler/ I do not understand its meaning there!
Browserify uses piler as well e.g, https://github./robrichard/browserify-pile-templates "Compiles underscore templates from HTML script tags into CommonJS in a browserify transform"
Share edited Mar 8, 2018 at 2:40 Qiulang asked Jan 7, 2018 at 6:34 QiulangQiulang 12.6k21 gold badges97 silver badges154 bronze badges 2- Possible duplicate of Is Babel a piler or transpiler? – Yangshun Tay Commented Jan 7, 2018 at 6:41
- @Yangshun Tay, it is not a duplicated question. See my update. – Qiulang Commented Jan 7, 2018 at 6:55
3 Answers
Reset to default 7It's better to describe the process as "transpilation."
Javascript always executes in a specific environment: in Chrome and Electron, it's the V8 engine; in Firefox, it's SpiderMonkey; etc. Each of these engines supports a specific set of language features and not others. As an example, some engines only support var
and do not support const
or let
. Some support async
/await
, and others only support Promise
.
But web developers know about these other features, and they want to use them, even when they're writing for an engine that doesn't support those features. Why? Most new language features are designed with the goal of making it possible to express plicated concepts in simpler and cleaner ways. This is extremely important, because the number one job of code is to make its purpose clear.
Thus, most language features are essentially syntactic sugar for existing functionality. In those cases, it's always possible to express a routine using both new and old syntax. This is a logical necessity.
A transpiler like Babel can read a script written using advanced syntax, and then re-express the script using a restricted set of language features. Relying on an intermediate representation called an abstract syntax tree, it can produce code that is guaranteed to be functionally equivalent, even though it does the work using very different, more widely-supported control structures.
Perhaps we web developers have gotten lazy in our terminology. When we talk of "piling" javascript, we aren't usually talking about converting the script to something like bytecode. We're talking about transpilation.
Other kinds of build tasks are also being quite mon. These days, the front-end is obsessed with a million flavors of "templating," because it's extremely tedious and confusing to describe DOM changes using pure javascript, and because application plexity is increasingly very rapidly. Some frameworks require you to convert source code to other intermediary forms that are later consumed by the web application at runtime. Others permit devs to describe UI using invented syntaxes that no browser is even attempting to support natively. Which tasks are needed varies by application depending on which frameworks are being used, the particulars of the application architecture, and the contours of the deployment environment, and that's just a start.
At its foundation, a web page is built using HTML, CSS, and javascript. That much hasn't changed. But today, most serious applications are built almost entirely in javascript (or something very much like it) and sass. Building the application is the process of applying a set of transformations to the source code to yield the final artifacts in those three bedrock languages.
We lump all that stuff under the term "pile."
You pretty much hit the nail on the head. When the Compile (or more appropriately transpilation) operation happens on a JavaScript project it can mean a number of things. As you mentioned these could range from minification, applying polyfills, shims, or the literal act of "piling" the scripts into a single bundle file for platform/browser consumption.
Transpilation when using super sets of the JavaScript language such as TypeScript, ActionScript, or UnityScript describes the process of converting the source x-script back into native JavaScript which can be in turn be interpreted by a browser (since the browser doesn't recognize the superset languages).
However you are absolutely correct. We aren't piling our JavaScript into binary, but the term gets thrown around a lot which can lead to confusion. All that said, we are closing in on the age of adoption of WebAssembly and ASMJs which promises to bring the age of bytecode running in the browser which will bring about some interesting possibilities, but alas... That's a story for another day ;)
You're right when you say these front-end Javascript tools don't use the word pile in same context in what your used to with build tools for languages like C/C++. C/C++ pilers turn source code into machine code.
These JavaScript build tools-- like Webpack-- use the word pile in a sense thats more metaphorical than conventional.
When web build tools use the word pile, they're using it in the sense that they are transpiling, minifying (a.k.a uglyfying), and bundling the source files so they are better optimized for client browsers and network requests. (Smaller file sizes, better browser patibility, less HTTP requests from bundled assets, etc.)
本文标签:
版权声明:本文标题:webpack - What do those javascript front-end build tools mean when they say "compile" my js codes? - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744917479a2632081.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论