-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a React example authored in TSX #1045
Comments
```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.
There are two bits to it. First, you need to ensure Here's a package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver", "ts_library")
ts_library(
name = "playground",
module_name = "my-lib-playground",
module_root = "src",
srcs = glob(
include = ["src/**/*.ts", "src/**/*.tsx"],
exclude = ["**/__tests__/*"],
),
deps = ["//packages/core"],
tsconfig = "//:tsconfig.json",
)
ts_devserver(
name = "devserver",
deps = [
"//:node_modules/react/umd/react.development.js",
"//:node_modules/react-dom/umd/react-dom.development.js",
":playground",
],
entry_module = 'my_root/packages/playground/src/index',
serving_path = "/dist/bundle.js",
) Unfortunately, Facebook doesn't currently include module names in its AMD bundles, so you'd also need to edit // notice the first argument below is now 'react-dom'
typeof define === 'function' && define.amd ? define('react-dom', ['react'], factory) : I've opened a PR for Facebook to fix this upstream. When that is merged, this In the mean time, you may be able to work around it by serving the React AMD bundles as static files (rather than <script>
requirejs.config({
paths: {
'react': '/node_modules/react/umd/react.development.js',
'react-dom': '/node_modules/react-dom/umd/react-dom.development',
}
});
</script> |
```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.
@appsforartists they are looking for you over in facebook/react#12019 |
re-purposing this issue to make an example for react |
This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?" |
Is it possible for rules_typescript to compile ReactJS? I tried a bit and found that it can generate the bundle.js but in the devserver it's not running.
Here is the generated bundle.js:
Looks like the anonymous factory function was never called. Both requirejs and amd was installed with yarn.
Any help? Thanks.
The text was updated successfully, but these errors were encountered: