File tree Expand file tree Collapse file tree
examples/create-react-app Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,11 +29,6 @@ copy_to_bin(
2929 ],
3030)
3131
32- copy_to_bin (
33- name = "copy_test_files" ,
34- srcs = glob (_TESTS ),
35- )
36-
3732# react-scripts can only work if the working directory is the root of the application.
3833# So we'll need to chdir before it runs.
3934write_file (
@@ -42,23 +37,31 @@ write_file(
4237 content = ["process.chdir(__dirname)" ],
4338)
4439
40+ _RUNTIME_DEPS = [
41+ "chdir.js" ,
42+ "copy_static_files" ,
43+ "@npm//react" ,
44+ "@npm//react-dom" ,
45+ ]
46+
4547react_scripts (
4648 # Note: this must be named "build" since react-scripts hard-codes that as the output dir
4749 name = "build" ,
4850 args = [
4951 "--node_options=--require=./$(execpath chdir.js)" ,
5052 "build" ,
5153 ],
52- data = [
53- "chdir.js" ,
54- "copy_static_files" ,
54+ data = _RUNTIME_DEPS + [
5555 "@npm//@types" ,
56- "@npm//react" ,
57- "@npm//react-dom" ,
5856 ],
5957 output_dir = True ,
6058)
6159
60+ copy_to_bin (
61+ name = "copy_test_files" ,
62+ srcs = glob (_TESTS ),
63+ )
64+
6265react_scripts_test (
6366 name = "test" ,
6467 args = [
@@ -71,15 +74,20 @@ react_scripts_test(
7174 "--no-watchman" ,
7275 "--ci" ,
7376 ],
74- data = [
75- "chdir.js" ,
76- "copy_static_files" ,
77+ data = _RUNTIME_DEPS + [
7778 "copy_test_files" ,
7879 "@npm//@testing-library/dom" ,
7980 "@npm//@testing-library/jest-dom" ,
8081 "@npm//@testing-library/react" ,
8182 "@npm//@testing-library/user-event" ,
82- "@npm//react" ,
83- "@npm//react-dom" ,
8483 ],
8584)
85+
86+ react_scripts (
87+ name = "start" ,
88+ args = [
89+ "--node_options=--require=$(rootpath chdir.js)" ,
90+ "start" ,
91+ ],
92+ data = _RUNTIME_DEPS ,
93+ )
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ approaches you can take to build and test your React app with Bazel.
66
77## Available Scripts
88
9- In the project directory, you can run:
9+ Just like with stock create-react-app, we have the same developer workflow. In the project directory, you can run:
1010
1111### ` yarn start `
1212
@@ -19,7 +19,9 @@ You will also see any lint errors in the console.
1919### ` yarn test `
2020
2121Launches the test runner in the interactive watch mode.<br />
22- See the section about [ running tests] ( https://facebook.github.io/create-react-app/docs/running-tests ) for more information.
22+ Note that it restarts Jest on each change, so there's a large time penalty on each re-run.
23+ This can be solved by making Jest ibazel-aware as we did with Karma.
24+ See https://github.com/bazelbuild/rules_nodejs/issues/2028
2325
2426### ` yarn build `
2527
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ function App() {
88 < header className = "App-header" >
99 < img src = { logo } className = "App-logo" alt = "logo" />
1010 < p >
11- Edit < code > src/App.tsx</ code > and save to reload.
11+ Edit < code > src/App.tsx</ code > and saverate to reload.
1212 </ p >
1313 < a
1414 className = "App-link"
You can’t perform that action at this time.
0 commit comments