Skip to content

Commit

Permalink
bundle resolution in code splitting (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshKyd authored and DeMoorJasper committed Jan 10, 2019
1 parent c48abea commit dfda814
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/i18n/en/docs/code_splitting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Parcel supports zero configuration code splitting out of the box. This allows yo

Code splitting is controlled by use of the dynamic `import()` function [syntax proposal](https://github.com/tc39/proposal-dynamic-import), which works like the normal `import` statement or `require` function, but returns a Promise. This means that the module is loaded asynchronously.

## Using dynamic imports

The following example shows how you might use dynamic imports to load a sub-page of your application on demand.

```javascript
Expand All @@ -20,6 +22,8 @@ import('./pages/about').then(function(page) {
})
```

## Dynamic imports with async/await

Because `import()` returns a Promise, you can also use async/await syntax. You probably need to configure Babel to transpile the syntax though, until it is more widely supported by browsers.

```javascript
Expand Down Expand Up @@ -57,3 +61,11 @@ import './app'
```

Read the docs on [babel-polyfill](http://babeljs.io/docs/usage/polyfill) and [babel-runtime](http://babeljs.io/docs/plugins/transform-runtime).

## Bundle resolution

Parcel infers the location of bundles automatically. This is done in the [bundle-url](https://github.com/parcel-bundler/parcel/blob/master/packages/core/parcel-bundler/src/builtins/bundle-url.js) module, and uses the stack trace to determine the path where the initial bundle was loaded.

This means you don't need to configure where bundles should be loaded from, but also means you must serve the bundles from the same location.

Parcel currently resolves bundles at the following protocols: `http`, `https`, `file`, `ftp`, `chrome-extension` and `moz-extension`.

1 comment on commit dfda814

@vercel
Copy link

@vercel vercel bot commented on dfda814 Jan 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.