Skip to content

Commit e84eb2a

Browse files
committed
build(craco): WIP on bundle for web
1 parent e5fe481 commit e84eb2a

File tree

6 files changed

+158
-4
lines changed

6 files changed

+158
-4
lines changed

craco.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
const appDirectory = fs.realpathSync(process.cwd())
5+
const resolveApp = relativePath => path.resolve(appDirectory, relativePath)
6+
const appIncludes = [resolveApp('src')]
7+
module.exports = {
8+
babel: {
9+
plugins: ['@babel/plugin-proposal-class-properties'],
10+
},
11+
webpack: {
12+
configure: (config, { env, paths }) => {
13+
config.module.rules[0].include = appIncludes
14+
config.module.rules[1] = null
15+
config.module.rules[2].oneOf[1].include = appIncludes
16+
config.module.rules[2].oneOf[1].options.plugins = [
17+
require.resolve('babel-plugin-react-native-web'),
18+
].concat(config.module.rules[2].oneOf[1].options.plugins)
19+
20+
const vectorIcons = {
21+
test: /\.ttf$/,
22+
loader: 'url-loader', // or directly file-loader
23+
include: path.resolve(
24+
__dirname,
25+
'node_modules/react-native-vector-icons',
26+
),
27+
}
28+
29+
config.module.rules.push(vectorIcons)
30+
config.module.rules = config.module.rules.filter(Boolean) // Clear null rules
31+
32+
config.plugins[9].tsconfig = resolveApp('tsconfig.web.json')
33+
34+
return config
35+
},
36+
},
37+
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"homepage": "https://example.barajs.dev",
77
"scripts": {
88
"dev": "run-p start:web start:mobile start:desktop",
9-
"start:web": "react-scripts start",
9+
"start:web": "craco start --verbose",
1010
"start:mobile": "node node_modules/react-native/local-cli/cli.js start",
1111
"start:desktop": "cross-env BROWSER=none concurrently \"yarn compile:desktop -w\" \"wait-on http://localhost:3000 && yarn watch:desktop\"",
1212
"watch:desktop": "nodemon --watch dist --exec \"electron ./dist\"",
@@ -38,7 +38,10 @@
3838
},
3939
"devDependencies": {
4040
"@babel/core": "7.4.3",
41+
"@babel/plugin-proposal-class-properties": "7.4.0",
42+
"@babel/polyfill": "7.4.3",
4143
"@babel/runtime": "7.4.3",
44+
"@craco/craco": "4.1.0",
4245
"@types/electron-devtools-installer": "2.2.0",
4346
"@types/electron-store": "1.3.1",
4447
"@types/jest": "24.0.11",
@@ -48,6 +51,7 @@
4851
"@types/react": "16.8.13",
4952
"@types/react-native": "0.57.45",
5053
"@types/react-test-renderer": "16.8.1",
54+
"babel-plugin-react-native-web": "0.11.2",
5155
"concurrently": "4.1.0",
5256
"cross-env": "5.2.0",
5357
"electron": "4.1.4",
@@ -59,6 +63,7 @@
5963
"nodemon": "1.18.11",
6064
"npm-run-all": "4.1.5",
6165
"prettier": "1.17.0",
66+
"react-app-polyfill": "0.2.2",
6267
"react-scripts": "2.1.8",
6368
"react-test-renderer": "16.8.6",
6469
"shx": "0.3.2",

src/index.css

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
::-webkit-scrollbar {
2+
width: 1px;
3+
height: 1px;
4+
background-color: transparent;
5+
}
6+
7+
::-webkit-scrollbar-thumb
8+
{
9+
background-color: transparent;
10+
}
11+
12+
*:focus {
13+
outline-color: #49d3b4;
14+
}
15+
16+
*[tabIndex^="-1"]:focus {
17+
outline: none;
18+
}
19+
20+
html, body, #root, #root > div {
21+
width: 100%;
22+
height: 100%;
23+
overflow: hidden;
24+
}
25+
26+
html {
27+
scroll-behavior: smooth;
28+
}
29+
30+
body {
31+
background-color: #292C33;
32+
text-rendering: optimizeLegibility;
33+
-webkit-font-smoothing: antialiased;
34+
-moz-osx-font-smoothing: grayscale;
35+
}
36+
37+
a:hover, a:hover > *:not([class*='touchAction']) {
38+
text-decoration: underline;
39+
}
40+
41+
input:focus {
42+
outline: none !important;
43+
}
44+
45+
/* https://github.com/necolas/react-native-web/issues/1299 */
46+
.pagingEnabledFix > div > div > div {
47+
height: 100%;
48+
}
49+

src/index.js renamed to src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
* @format
33
*/
44

5+
// Security precaution
6+
;(window as any).eval = global.eval = (payload: string) => {
7+
const error = new Error(`This app does not allow window.eval().`)
8+
Object.assign(error, { payload })
9+
10+
throw error
11+
}
12+
13+
import '@babel/polyfill'
14+
import 'react-app-polyfill/ie9'
15+
516
import { register } from 'bara'
617
import { useReactApp } from 'bara-react'
718
import App from './App'

tsconfig.web.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"allowJs": false,
5+
"forceConsistentCasingInFileNames": true,
6+
"isolatedModules": true,
7+
"jsx": "preserve",
8+
"noEmit": true,
9+
"outDir": "dist",
10+
"rootDir": "src"
11+
},
12+
"include": [
13+
"src/index.ts"
14+
],
15+
"exclude": [
16+
"src/setupProxy.js"
17+
]
18+
}

yarn.lock

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
"@babel/helper-create-class-features-plugin" "^7.3.0"
293293
"@babel/helper-plugin-utils" "^7.0.0"
294294

295-
"@babel/plugin-proposal-class-properties@^7.0.0":
295+
"@babel/plugin-proposal-class-properties@7.4.0", "@babel/plugin-proposal-class-properties@^7.0.0":
296296
version "7.4.0"
297297
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.4.0.tgz#d70db61a2f1fd79de927eea91f6411c964e084b8"
298298
integrity sha512-t2ECPNOXsIeK1JxJNKmgbzQtoG27KIlVE61vTqX0DKR9E9sZlVVxWUtEW9D5FlZ8b8j7SBNCHY47GgPKCKlpPg==
@@ -820,6 +820,14 @@
820820
"@babel/helper-regex" "^7.4.3"
821821
regexpu-core "^4.5.4"
822822

823+
824+
version "7.4.3"
825+
resolved "https://registry.yarnpkg.com/@babel/polyfill/-/polyfill-7.4.3.tgz#332dc6f57b718017c3a8b37b4eea8aa6eeac1187"
826+
integrity sha512-rkv8WIvJshA5Ev8iNMGgz5WZkRtgtiPexiT7w5qevGTuT7ZBfM3de9ox1y9JR5/OXb/sWGBbWlHNa7vQKqku3Q==
827+
dependencies:
828+
core-js "^2.6.5"
829+
regenerator-runtime "^0.13.2"
830+
823831
824832
version "7.3.1"
825833
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.3.1.tgz#389e8ca6b17ae67aaf9a2111665030be923515db"
@@ -1031,6 +1039,15 @@
10311039
dependencies:
10321040
xstream "11.10.0"
10331041

1042+
1043+
version "4.1.0"
1044+
resolved "https://registry.yarnpkg.com/@craco/craco/-/craco-4.1.0.tgz#f8ffbce0324c2d68fd025291a8c1866359bbecfd"
1045+
integrity sha512-yaCjyC2GKFsAMZRtBkB61ZSAPcuEn5U3PKRTc+Cwy0IW5KgLDposutT9np44AfaZXOw1kd9Z0bgy+f0HiB9vNg==
1046+
dependencies:
1047+
cross-spawn "6.0.5"
1048+
lodash.mergewith "4.6.1"
1049+
webpack-merge "4.1.4"
1050+
10341051
"@csstools/convert-colors@^1.4.0":
10351052
version "1.4.0"
10361053
resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7"
@@ -2113,6 +2130,11 @@ babel-plugin-named-asset-import@^0.3.1:
21132130
resolved "https://registry.yarnpkg.com/babel-plugin-named-asset-import/-/babel-plugin-named-asset-import-0.3.1.tgz#5ec13ec446d0a1e5bb6c57a1f94c9cdedb0c50d6"
21142131
integrity sha512-vzZlo+yEB5YHqI6CRRTDojeT43J3Wf3C/MVkZW5UlbSeIIVUYRKtxaFT2L/VTv9mbIyatCW39+9g/SZolvwRUQ==
21152132

2133+
2134+
version "0.11.2"
2135+
resolved "https://registry.yarnpkg.com/babel-plugin-react-native-web/-/babel-plugin-react-native-web-0.11.2.tgz#a1b9ab25fcd48936823d4ec537c749c007ceaf15"
2136+
integrity sha512-nZwvX8/HA3w6zkpDs1If9aIkHTyvuClAmLtSPJTmy7lXixX9z7/Siap/yjIaCp0Hz5gC5ALFXLBQv8oSdEqtQA==
2137+
21162138
babel-plugin-syntax-object-rest-spread@^6.13.0, babel-plugin-syntax-object-rest-spread@^6.8.0:
21172139
version "6.13.0"
21182140
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5"
@@ -3328,7 +3350,7 @@ core-js@^1.0.0:
33283350
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
33293351
integrity sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=
33303352

3331-
core-js@^2.2.2, core-js@^2.4.0, core-js@^2.4.1, core-js@^2.5.0, core-js@^2.5.7:
3353+
core-js@^2.2.2, core-js@^2.4.0, core-js@^2.4.1, core-js@^2.5.0, core-js@^2.5.7, core-js@^2.6.5:
33323354
version "2.6.5"
33333355
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895"
33343356
integrity sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A==
@@ -7498,6 +7520,11 @@ lodash.memoize@^4.1.2:
74987520
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
74997521
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
75007522

7523+
7524+
version "4.6.1"
7525+
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927"
7526+
integrity sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ==
7527+
75017528
lodash.pad@^4.1.0:
75027529
version "4.5.1"
75037530
resolved "https://registry.yarnpkg.com/lodash.pad/-/lodash.pad-4.5.1.tgz#4330949a833a7c8da22cc20f6a26c4d59debba70"
@@ -10224,7 +10251,7 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.2.1, rc@^1.2.7:
1022410251
minimist "^1.2.0"
1022510252
strip-json-comments "~2.0.1"
1022610253

10227-
react-app-polyfill@^0.2.2:
10254+
react-app-polyfill@0.2.2, react-app-polyfill@^0.2.2:
1022810255
version "0.2.2"
1022910256
resolved "https://registry.yarnpkg.com/react-app-polyfill/-/react-app-polyfill-0.2.2.tgz#a903b61a8bfd9c5e5f16fc63bebe44d6922a44fb"
1023010257
integrity sha512-mAYn96B/nB6kWG87Ry70F4D4rsycU43VYTj3ZCbKP+SLJXwC0x6YCbwcICh3uW8/C9s1VgP197yx+w7SCWeDdQ==
@@ -12804,6 +12831,13 @@ [email protected]:
1280412831
lodash ">=3.5 <5"
1280512832
tapable "^1.0.0"
1280612833

12834+
12835+
version "4.1.4"
12836+
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.4.tgz#0fde38eabf2d5fd85251c24a5a8c48f8a3f4eb7b"
12837+
integrity sha512-TmSe1HZKeOPey3oy1Ov2iS3guIZjWvMT2BBJDzzT5jScHTjVC3mpjJofgueEzaEd6ibhxRDD6MIblDr8tzh8iQ==
12838+
dependencies:
12839+
lodash "^4.17.5"
12840+
1280712841
webpack-sources@^1.1.0, webpack-sources@^1.3.0:
1280812842
version "1.3.0"
1280912843
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.3.0.tgz#2a28dcb9f1f45fe960d8f1493252b5ee6530fa85"

0 commit comments

Comments
 (0)