diff --git a/docs/en/getting-started.html b/docs/en/getting-started.html index 255405c6..5ffeba80 100644 --- a/docs/en/getting-started.html +++ b/docs/en/getting-started.html @@ -32,13 +32,13 @@ app.use.processRequest.bind(metroBundlerServer), ); -app.listen(8081);

Method build(serverOptions, bundleOptions) #

Given a set of options that you would typically pass to a server, plus a set of options specific to the bundle itself, a bundle will be built. The return value is a Promise that resolves to an object with two properties, code and map. This is useful at build time.

Available options #

Possible server options #

Possible bundle options: #

URL and bundle request #

The server has the ability to serve assets, bundles and source maps for those bundles.

Assets #

In order to request an asset, you can freely use the require method as if it was another JS file. The server will treat this specific require calls and make them return the path to that file. When an asset is requested (an asset is recognized by its extension, which has to be on the assetExts array) it is generally served as-is.

However, the server is also able to serve specific assets depending on the platform and on the requested size (in the case of images). The way you specify the platform is via the dotted suffix (e.g. .ios) and the resolution via the at suffix (e.g. @2x). This is transparently handled for you when using require.

Bundle #

Any JS file can be used as the root for a bundle request. The file will be looked into each of the project roots provided (via the projectRoots property of the server). All files that are required by the root will be recursively included. In order to request a bundle, just change the extension from .js to .bundle. Options for building the bundle are passed as query parameters (all optional).

For instance, requesting http://localhost:8081/foo/bar/baz.bundle?dev=true&platform=ios will create a bundle out of foo/bar/baz.js for iOS in development mode.

Source maps #

Source maps are built for each bundle by using the same URL as the bundle (thus, the same as the JS file acting as a root). This will only work when inlineSourceMap is set to false. All options you passed to the bundle will be added to the source map URL; otherwise, they wouldn't match.

JavaScript transformer #

The JavaScript transformer (transformModulePath) is the place where JS code will be manipulated; useful for calling Babel. The transformer can export two methods:

Method transform(module) #

Mandatory method that will transform code. The object received has information about the module being transformed (e.g its path, code...) and the returned object has to contain an ast key that is the AST representation of the transformed code. The default shipped transformer does the bare minimum amount of work by just parsing the code to AST:

const babylon = require('babylon');
+app.listen(8081);

Method build(serverOptions, bundleOptions) #

Given a set of options that you would typically pass to a server, plus a set of options specific to the bundle itself, a bundle will be built. The return value is a Promise that resolves to an object with two properties, code and map. This is useful at build time.

Available options #

Possible server options #

Possible bundle options: #

URL and bundle request #

The server has the ability to serve assets, bundles and source maps for those bundles.

Assets #

In order to request an asset, you can freely use the require method as if it was another JS file. The server will treat this specific require calls and make them return the path to that file. When an asset is requested (an asset is recognized by its extension, which has to be on the assetExts array) it is generally served as-is.

However, the server is also able to serve specific assets depending on the platform and on the requested size (in the case of images). The way you specify the platform is via the dotted suffix (e.g. .ios) and the resolution via the at suffix (e.g. @2x). This is transparently handled for you when using require.

Bundle #

Any JS file can be used as the root for a bundle request. The file will be looked into each of the project roots provided (via the projectRoots property of the server). All files that are required by the root will be recursively included. In order to request a bundle, just change the extension from .js to .bundle. Options for building the bundle are passed as query parameters (all optional).

For instance, requesting http://localhost:8081/foo/bar/baz.bundle?dev=true&platform=ios will create a bundle out of foo/bar/baz.js for iOS in development mode.

Source maps #

Source maps are built for each bundle by using the same URL as the bundle (thus, the same as the JS file acting as a root). This will only work when inlineSourceMap is set to false. All options you passed to the bundle will be added to the source map URL; otherwise, they wouldn't match.

JavaScript transformer #

The JavaScript transformer (transformModulePath) is the place where JS code will be manipulated; useful for calling Babel. The transformer can export two methods:

Method transform(module) #

Mandatory method that will transform code. The object received has information about the module being transformed (e.g its path, code...) and the returned object has to contain an ast key that is the AST representation of the transformed code. The default shipped transformer does the bare minimum amount of work by just parsing the code to AST:

const babylon = require('babylon7');
 
 module.exports.transform = (file: {filename: string, src: string}) => {
   const ast = babylon.parse(code, {sourceType: 'module'});
 
   return {ast};
-};

If you would like to plug-in babel, you can simply do that by passing the code to it:

const {transform} = require('babel-core');
+};

If you would like to plug-in babel, you can simply do that by passing the code to it:

const {transform} = require('@babel/core');
 
 module.exports.transform = file => {
   return transform(file.src, {