Skip to content

Commit

Permalink
Use package.json names for AMD bundles
Browse files Browse the repository at this point in the history
```js
define('', ['require', 'exports', 'react', 'react-dom'] // …
  var React = require('react');
```

throws a [mismatched define error](https://requirejs.org/docs/errors.html#mismatch) when used with RequireJS because the current AMD definitions don't specify module names.  This patch passes the bundle names into `rollup`, so the AMD definitions can use them.

By naming the builds, they can be [consumed from the Bazel build tool](https://github.com/bazelbuild/rules_typescript/issues/102).

I have minimal familiarity with AMD.  I don't believe adding module names should affect other environments.
  • Loading branch information
appsforartists committed Jan 14, 2018
1 parent 3766a01 commit c38f3c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
9 changes: 6 additions & 3 deletions scripts/rollup/build.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,19 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
}
}

function getRollupOutputOptions(outputPath, format, globals, globalName) {
function getRollupOutputOptions(outputPath, format, globals, bundle) {
return Object.assign(
{},
{
file: outputPath,
format,
globals,
interop: false,
name: globalName,
name: bundle.global,
sourcemap: false,
amd: {
id: bundle.entry,
},
}
);
}
Expand Down Expand Up @@ -379,7 +382,7 @@ async function createBundle(bundle, bundleType) {
mainOutputPath,
format,
peerGlobals,
bundle.global
bundle
);

console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`);
Expand Down
24 changes: 12 additions & 12 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"filename": "react.development.js",
"bundleType": "UMD_DEV",
"packageName": "react",
"size": 55375,
"gzip": 15018
"size": 55384,
"gzip": 15020
},
{
"filename": "react.production.min.js",
Expand Down Expand Up @@ -46,8 +46,8 @@
"filename": "react-dom.development.js",
"bundleType": "UMD_DEV",
"packageName": "react-dom",
"size": 561031,
"gzip": 132753
"size": 560474,
"gzip": 132549
},
{
"filename": "react-dom.production.min.js",
Expand Down Expand Up @@ -88,8 +88,8 @@
"filename": "react-dom-test-utils.development.js",
"bundleType": "UMD_DEV",
"packageName": "react-dom",
"size": 41264,
"gzip": 11741
"size": 41564,
"gzip": 11896
},
{
"filename": "react-dom-test-utils.production.min.js",
Expand Down Expand Up @@ -123,8 +123,8 @@
"filename": "react-dom-unstable-native-dependencies.development.js",
"bundleType": "UMD_DEV",
"packageName": "react-dom",
"size": 63124,
"gzip": 16553
"size": 63166,
"gzip": 16560
},
{
"filename": "react-dom-unstable-native-dependencies.production.min.js",
Expand Down Expand Up @@ -165,8 +165,8 @@
"filename": "react-dom-server.browser.development.js",
"bundleType": "UMD_DEV",
"packageName": "react-dom",
"size": 93545,
"gzip": 25061
"size": 94147,
"gzip": 25200
},
{
"filename": "react-dom-server.browser.production.min.js",
Expand Down Expand Up @@ -221,8 +221,8 @@
"filename": "react-art.development.js",
"bundleType": "UMD_DEV",
"packageName": "react-art",
"size": 357962,
"gzip": 80313
"size": 358044,
"gzip": 80316
},
{
"filename": "react-art.production.min.js",
Expand Down

0 comments on commit c38f3c8

Please sign in to comment.