-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: 沈青川 <46062972+ShenQingchuan@users.noreply.github.com>
- Loading branch information
1 parent
1e85989
commit 0ceb9e3
Showing
30 changed files
with
75 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"title": "Tree-shaking", | ||
"title": "除屑优化(Tree-shaking)", | ||
"options": { | ||
"treeshake": true | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// TREE-SHAKING | ||
// 除屑优化 | ||
import { cube } from './maths.js'; | ||
|
||
console.log(cube(5)); // 125 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
// maths.js | ||
|
||
// This function isn't used anywhere, so | ||
// Rollup excludes it from the bundle... | ||
// 这个函数并没有被外部模块使用 | ||
// 所以 Rollup 会将它从打包产物中排除掉... | ||
export const square = x => x * x; | ||
|
||
// This function gets included | ||
// rewrite this as `square(x) * x` | ||
// and see what happens! | ||
// 这个函数被外部模块使用了 | ||
// 把这个函数重写为 `square(x) * x` | ||
// 看看会发生什么。 | ||
export const cube = x => x * x * x; | ||
|
||
// This "side effect" creates a global | ||
// variable and will not be removed. | ||
// 这个“副作用”创建了一个全局变量 | ||
// 所以它不会被移除。 | ||
window.effect1 = 'created'; | ||
|
||
const includeEffect = false; | ||
if (includeEffect) { | ||
// On the other hand, this is never | ||
// executed and thus removed. | ||
// 另一方面来说,这将永远不会被执行 | ||
// 所以会被移除。 | ||
window.effect1 = 'not created'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"title": "Named exports", | ||
"title": "具名导出(Named exports)", | ||
"options": { | ||
"output": { | ||
"exports": "auto", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"title": "Default exports", | ||
"title": "默认导出(Default exports)", | ||
"options": { | ||
"output": { | ||
"exports": "auto", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Internal default exports are turned | ||
// into variables | ||
// 内部默认导出会被 | ||
// 转换为变量 | ||
export default 42; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// DEFAULT EXPORTS | ||
// Default exports from the 'entry module' are | ||
// exported from the bundle | ||
// 默认导出 | ||
// 从“入口模块”默认导出的内容会被打包后导出 | ||
import answer from './answer.js'; | ||
|
||
export default () => console.log('the answer is ' + answer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"title": "Static namespaces" | ||
"title": "静态名称空间" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// STATIC NAMESPACES | ||
// ES6 modules let you import all of another module's | ||
// exports as a namespace... | ||
// 静态名称空间 | ||
// ES6 模块允许你 | ||
// 将另一个模块的所有导出都作为命名空间导入... | ||
import * as assert from './assert'; | ||
|
||
// ...but we can statically resolve this to the | ||
// original function definition | ||
// ...但我们可以静态地 | ||
// 将其解析为原始函数定义 | ||
assert.equal(1 + 1, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"title": "Dynamic namespaces", | ||
"title": "动态名称空间", | ||
"options": { | ||
"output": { | ||
"freeze": "true" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"title": "External imports", | ||
"title": "外部导入", | ||
"options": { | ||
"output": { | ||
"globals": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// EXTERNAL IMPORTS | ||
// You can import external modules into your bundle – | ||
// it doesn't matter if they're ES2015 or legacy | ||
// 外部导入 | ||
// 您可以将外部模块导入到你的打包产物中 - | ||
// 不用在意那些代码是 ES 模块还是其他兼容格式 | ||
import $ from 'jquery'; | ||
|
||
$('body').html('<h1>Hello world!</h1>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"title": "Dynamic imports", | ||
"title": "动态导入", | ||
"options": { | ||
"output": { | ||
"inlineDynamicImports": false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Modules shared between the entry chunk and the | ||
// dynamic chunk are merged into the entry chunk. | ||
// 在入口块和动态块之间共享的模块 | ||
// 将合并到入口块中。 | ||
export default x => x * x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import square from './square.js'; | ||
|
||
// Everything used by both entry modules will become | ||
// a separate chunk that is imported by both entry | ||
// chunks to avoid code duplication | ||
// 两个入口模块都使用的所有内容都将成为一个单独的代码块, | ||
// 由两个入口代码块导入 | ||
// 以避免代码重复 | ||
export default function cube(x) { | ||
return square(x) * x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import cube from './cube.js'; | ||
|
||
// This is only imported by one entry module and | ||
// shares a chunk with that module | ||
// 这只被一个入口模块导入 | ||
// 并与该模块共享一个代码块 | ||
export default function hyperCube(x) { | ||
return cube(x) * x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// MULTIPLE ENTRY MODULES | ||
// 多个入口模块 | ||
import hyperCube from './hyperCube.js'; | ||
|
||
console.log(hyperCube(5)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Additional entry modules create new chunks | ||
// 额外的入口模块会创建新的代码块。 | ||
import cube from './cube.js'; | ||
|
||
console.log(cube(5)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// This is also shared between the entry chunks | ||
// 这也在入口代码块之间共享。 | ||
export default function square(x) { | ||
return x * x; | ||
} |