Rich-Harris
9 years ago
15 changed files with 44 additions and 44 deletions
@ -1,3 +0,0 @@ |
|||
export function foo () { |
|||
return 42; |
|||
} |
@ -1,2 +1,2 @@ |
|||
import { foo } from './foo'; |
|||
console.log( foo() ); |
|||
import { cube } from './maths.js'; |
|||
console.log( cube( 5 ) ); // 125
|
|||
|
@ -0,0 +1,12 @@ |
|||
// This function isn't used anywhere, so
|
|||
// Rollup excludes it from the bundle...
|
|||
export function square ( x ) { |
|||
return x * x; |
|||
} |
|||
|
|||
// This function gets included
|
|||
export function cube ( x ) { |
|||
// rewrite this as `square( x ) * x`
|
|||
// and see what happens!
|
|||
return x * x * x; |
|||
} |
@ -1 +1 @@ |
|||
first example |
|||
Tree-shaking |
|||
|
@ -0,0 +1 @@ |
|||
export default 42; |
@ -1,9 +0,0 @@ |
|||
export const sqrt = Math.sqrt; |
|||
|
|||
export function square( x ) { |
|||
return x * x; |
|||
} |
|||
|
|||
export function diag ( x, y ) { |
|||
return sqrt( square( x ) + square( y ) ); |
|||
} |
@ -1,3 +1,7 @@ |
|||
import { diag } from './lib'; |
|||
import answer from './answer.js'; |
|||
|
|||
console.log( diag( 3, 4 ) ); // 5
|
|||
// Default exports from the 'entry module' are
|
|||
// exported from the bundle
|
|||
export default function () { |
|||
console.log( 'the answer is ' + answer ); |
|||
} |
|||
|
@ -1 +1 @@ |
|||
second example |
|||
Default exports |
|||
|
@ -1,4 +1,14 @@ |
|||
import { getStringTag } from './unbind'; |
|||
import { arrayTag } from './tags'; |
|||
// There are many ways to export bindings
|
|||
// from an ES2015 module
|
|||
export var foo = 1; |
|||
|
|||
console.log( getStringTag( [] ) === arrayTag ); // true
|
|||
export function bar () { |
|||
return foo; // try changing this to `foo++`
|
|||
} |
|||
|
|||
function baz () { |
|||
return bar(); |
|||
} |
|||
|
|||
export { baz }; |
|||
export * from './qux'; |
|||
|
@ -0,0 +1 @@ |
|||
export var qux = 'QUX'; |
@ -1,10 +0,0 @@ |
|||
// A number of StringTags.
|
|||
export const |
|||
arrayTag = '[object Array]', |
|||
dateTag = '[object Date]', |
|||
functionTag = '[object Function]', |
|||
mathTag = '[object Math]', |
|||
nullTag = '[object Null]', |
|||
regexTag = '[object RegExp]', |
|||
stringTag = '[object String]', |
|||
undefinedTag = '[object Undefined]'; |
@ -1,12 +0,0 @@ |
|||
// Create functions from prototype methods, to avoid using call.
|
|||
const unbind = Function.prototype.bind.bind(Function.prototype.call); |
|||
|
|||
export const slice = unbind(Array.prototype.slice); |
|||
|
|||
// Check if the first argument has a given property name.
|
|||
export const hasOwn = unbind(Object.prototype.hasOwnProperty); |
|||
|
|||
// Get the string tag of an object.
|
|||
export const getStringTag = unbind(Object.prototype.toString); |
|||
|
|||
export default unbind; |
@ -1 +1 @@ |
|||
deadcode-elimination |
|||
Named exports |
|||
|
@ -0,0 +1,5 @@ |
|||
// You can import external modules into your bundle –
|
|||
// it doesn't matter if they're ES2015 or legacy
|
|||
import $ from 'jquery'; |
|||
|
|||
$( 'body' ).html( '<h1>Hello world!</h1>' ); |
@ -0,0 +1 @@ |
|||
External imports |
Loading…
Reference in new issue