Skip to content

Commit bbd0788

Browse files
committed
bundle without scalajs-bundler
1 parent ad63cef commit bbd0788

20 files changed

+3392
-805
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ bin/
4646

4747
#general
4848
*.class
49-
/node_modules
49+
node_modules

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Terraform deployment:
1414

1515
## Requirements
1616

17-
- aws-cli
1817
- sbt
1918
- yarn
2019
- node (>= 10.13.0)
20+
- aws-cli
2121
- terraform (>= 1.0.0): https://www.terraform.io/downloads.html
2222

2323
## Development
@@ -33,11 +33,6 @@ Changing any source file will automatically recompile and hot-reload the website
3333

3434
To know more about the details, have a look at [dev.sh](dev.sh)
3535

36-
If you just want to develop on your frontend without any backend:
37-
```sh
38-
sbt devf
39-
```
40-
4136
#### Infos about webapp
4237

4338
Webpack configuration: `webapp/webpack.config.dev.js`, `webapp/webpack.config.prod.js`
@@ -94,7 +89,7 @@ aws route53 get-hosted-zone --id $HOSTED_ZONE_ID | jq ".DelegationSet.NameServer
9489
First build the application:
9590

9691
```sh
97-
sbt prod
92+
./prod.sh
9893
```
9994

10095
Then go into the terraform directory. Set your `AWS_PROFILE`. And run terraform:

build.sbt

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,20 @@ lazy val commonSettings = Seq(
2121
)
2222

2323
lazy val jsSettings = Seq(
24-
webpack / version := "4.46.0",
25-
useYarn := true,
2624
scalaJSLinkerConfig ~= { _.withOptimizer(false) },
2725
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
2826
libraryDependencies += "org.portable-scala" %%% "portable-scala-reflect" % "1.1.2",
29-
)
3027

31-
def readJsDependencies(baseDirectory: File, field: String): Seq[(String, String)] = {
32-
val packageJson = ujson.read(IO.read(new File(s"$baseDirectory/package.json")))
33-
packageJson(field).obj.mapValues(_.str.toString).toSeq
34-
}
28+
externalNpm := {
29+
sys.process.Process("yarn", baseDirectory.value).!
30+
baseDirectory.value
31+
},
32+
)
3533

3634
lazy val webapp = project
3735
.enablePlugins(
3836
ScalaJSPlugin,
39-
ScalaJSBundlerPlugin,
40-
ScalablyTypedConverterPlugin,
37+
ScalablyTypedConverterExternalNpmPlugin,
4138
)
4239
.dependsOn(api)
4340
.settings(commonSettings, jsSettings)
@@ -49,26 +46,12 @@ lazy val webapp = project
4946
"com.github.cornerman" %%% "colibri-router" % versions.colibri,
5047
"io.suzaku" %%% "boopickle" % versions.boopickle,
5148
),
52-
Compile / npmDependencies ++= readJsDependencies(baseDirectory.value, "dependencies") ++ Seq(
53-
"snabbdom" -> "github:outwatch/snabbdom.git#semver:0.7.5", // for outwatch, workaround for: https://github.com/ScalablyTyped/Converter/issues/293
54-
"reconnecting-websocket" -> "4.1.10", // for fun-stack websockets, workaround for https://github.com/ScalablyTyped/Converter/issues/293 https://github.com/cornerman/mycelium/blob/6f40aa7018276a3281ce11f7047a6a3b9014bff6/build.sbt#74
55-
"jwt-decode" -> "3.1.2", // for fun-stack auth, workaround for https://github.com/ScalablyTyped/Converter/issues/293 https://github.com/cornerman/mycelium/blob/6f40aa7018276a3281ce11f7047a6a3b9014bff6/build.sbt#74
56-
),
5749
stIgnore ++= List(
5850
"reconnecting-websocket",
5951
"snabbdom",
6052
"jwt-decode",
6153
),
62-
Compile / npmDevDependencies ++= readJsDependencies(baseDirectory.value, "devDependencies"),
6354
scalaJSUseMainModuleInitializer := true,
64-
webpackDevServerPort := 12345,
65-
webpackDevServerExtraArgs := Seq("--color"),
66-
startWebpackDevServer / version := "3.11.3",
67-
fullOptJS / webpackEmitSourceMaps := true,
68-
fastOptJS / webpackEmitSourceMaps := true,
69-
fastOptJS / webpackBundlingMode := BundlingMode.LibraryOnly(),
70-
fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.dev.js"),
71-
fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.prod.js"),
7255
)
7356

7457
// shared project which contains api definitions.
@@ -87,8 +70,7 @@ lazy val api = project
8770
lazy val lambda = project
8871
.enablePlugins(
8972
ScalaJSPlugin,
90-
ScalaJSBundlerPlugin,
91-
ScalablyTypedConverterPlugin,
73+
ScalablyTypedConverterExternalNpmPlugin,
9274
)
9375
.dependsOn(api)
9476
.settings(commonSettings, jsSettings)
@@ -102,27 +84,14 @@ lazy val lambda = project
10284
"io.suzaku" %%% "boopickle" % versions.boopickle,
10385
"com.lihaoyi" %%% "pprint" % versions.pprint,
10486
),
105-
Compile / npmDependencies ++= readJsDependencies(baseDirectory.value, "dependencies"),
10687
stIgnore ++= List(
10788
"aws-sdk",
10889
),
109-
Compile / npmDevDependencies ++= readJsDependencies(baseDirectory.value, "devDependencies"),
110-
fullOptJS / webpackEmitSourceMaps := true,
111-
fastOptJS / webpackEmitSourceMaps := true,
112-
fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.dev.js"),
113-
fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.prod.js"),
11490
)
11591

116-
addCommandAlias("prod", "fullOptJS/webpack")
117-
addCommandAlias("prodf", "webapp/fullOptJS/webpack")
118-
addCommandAlias("prodb", "lambda/fullOptJS/webpack")
119-
addCommandAlias("dev", "devInitAll; devWatchAll; devDestroyFrontend")
120-
addCommandAlias("devf", "devInitFrontend; devWatchFrontend; devDestroyFrontend") // compile only frontend
121-
addCommandAlias("devb", "devInitBackend; devWatchBackend") // compile only backend
122-
addCommandAlias("devInitBackend", "lambda/fastOptJS/webpack")
123-
addCommandAlias("devInitFrontend", "webapp/fastOptJS/startWebpackDevServer; webapp/fastOptJS/webpack")
124-
addCommandAlias("devInitAll", "devInitFrontend; devInitBackend")
125-
addCommandAlias("devWatchFrontend", "~; webapp/fastOptJS")
126-
addCommandAlias("devWatchBackend", "~; lambda/fastOptJS")
127-
addCommandAlias("devWatchAll", "~; lambda/fastOptJS; webapp/fastOptJS")
128-
addCommandAlias("devDestroyFrontend", "webapp/fastOptJS/stopWebpackDevServer")
92+
addCommandAlias("prod", "fullOptJS")
93+
addCommandAlias("prodf", "webapp/fullOptJS")
94+
addCommandAlias("prodb", "lambda/fullOptJS")
95+
addCommandAlias("dev", "~; lambda/fastOptJS; webapp/fastOptJS")
96+
addCommandAlias("devf", "~; webapp/fastOptJS")
97+
addCommandAlias("devb", "~; lambda/fastOptJS")

dev.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,31 @@ prefix() (
2828
awk -v prefix="$colored_prefix" '{ print prefix $0; system("") }'
2929
)
3030

31+
(cd lambda && yarn install && npx webpack \
32+
bundle \
33+
--watch \
34+
--config webpack.config.dev.js \
35+
| prefix "WEBPACK_BACKEND" 4 & \
36+
)
37+
38+
(cd webapp && yarn install && npx webpack \
39+
serve \
40+
--port $PORT_FRONTEND \
41+
--config webpack.config.dev.js \
42+
| prefix "WEBPACK_FRONTEND" 4 & \
43+
)
44+
3145
yarn install
3246

3347
npx fun-local-env \
3448
--auth $PORT_AUTH \
3549
--ws $PORT_WS \
3650
--http $PORT_HTTP \
37-
--http-api lambda/target/scala-2.13/scalajs-bundler/main/lambda-fastopt.js httpApi \
38-
--http-rpc lambda/target/scala-2.13/scalajs-bundler/main/lambda-fastopt.js httpRpc \
39-
--ws-rpc lambda/target/scala-2.13/scalajs-bundler/main/lambda-fastopt.js wsRpc \
40-
--ws-event-authorizer lambda/target/scala-2.13/scalajs-bundler/main/lambda-fastopt.js wsEventAuth \
51+
--http-api lambda/target/dev/main.js httpApi \
52+
--http-rpc lambda/target/dev/main.js httpRpc \
53+
--ws-rpc lambda/target/dev/main.js wsRpc \
54+
--ws-event-authorizer lambda/target/dev/main.js wsEventAuth \
4155
| prefix "BACKEND" 4 &
4256

4357
sbt dev shell
4458
printf "\n"
45-
46-

lambda/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"aws-sdk": "2.1135.0"
44
},
55
"devDependencies": {
6-
"@fun-stack/fun-pack": "0.2.0"
6+
"@fun-stack/fun-pack": "0.2.2",
7+
"typescript": "4.3",
8+
"webpack": "4.46.0",
9+
"webpack-cli": "^4.9.2"
710
}
811
}

lambda/webpack.config.dev.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const {lambdaDev} = require('@fun-stack/fun-pack');
22

33
// https://github.com/fun-stack/fun-pack
4-
module.exports = lambdaDev();
4+
module.exports = lambdaDev({
5+
entrypoint: "target/scala-2.13/lambda-fastopt/main.js",
6+
outputDir: "target/dev/"
7+
});

lambda/webpack.config.prod.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const {lambdaProd} = require('@fun-stack/fun-pack');
22

33
// https://github.com/fun-stack/fun-pack
4-
module.exports = lambdaProd();
4+
module.exports = lambdaProd({
5+
entrypoint: "target/scala-2.13/lambda-opt/main.js",
6+
outputDir: "target/dist/"
7+
});

0 commit comments

Comments
 (0)