Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
PRJ-169 Reduce distribution size
Browse files Browse the repository at this point in the history
1. Switch building to webpack to make resources copy automatically
2. Get rid of copying the whole node_modules dir by `npm install`ing only required dependencies
  • Loading branch information
SerVB committed Nov 17, 2020
1 parent 7ef3040 commit e4b6b0f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 52 deletions.
28 changes: 8 additions & 20 deletions projector-launcher/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,20 @@ val npmCommand = when (DefaultNativePlatform.getCurrentOperatingSystem().isWindo
false -> listOf("npm")
}

val distElectron by tasks.creating(Exec::class) {
val npmInstall by tasks.creating(Exec::class) {
group = "dist"
workingDir(project.projectDir)
commandLine(npmCommand + listOf("run", "packager"))
workingDir(project.file("electronapp/build/distributions"))
commandLine(npmCommand + listOf("install"))
}

val copyDeps by tasks.creating(Copy::class) {
val runPackager by tasks.creating(Exec::class) {
group = "dist"
dependsOn(distElectron)

// inspired by https://stackoverflow.com/a/42133267/6639500
val filesToCopy = copySpec {
from("build/js/node_modules")
}

into("out")

val destinations = listOf(
"projector-linux-x64/resources/app/node_modules",
"projector-win32-x64/resources/app/node_modules",
"projector-darwin-x64/projector.app/Contents/Resources/app/node_modules"
)
destinations.forEach { into(it) { with(filesToCopy) } }
dependsOn(npmInstall)
workingDir(project.projectDir)
commandLine(npmCommand + listOf("run", "packager"))
}

tasks.create("dist") {
group = "dist"
dependsOn(copyDeps)
dependsOn(runPackager)
}
34 changes: 3 additions & 31 deletions projector-launcher/electronapp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin

plugins {
kotlin("js")
}
Expand All @@ -13,17 +10,9 @@ val kotlinExtensionsVersion: String by project

kotlin {
js {
nodejs {
compilations.all {
kotlinOptions {
kotlinOptions.moduleKind = "umd"
kotlinOptions.sourceMap = true
kotlinOptions.sourceMapEmbedSources = "always"
kotlinOptions.metaInfo = true
kotlinOptions.main = "call"
}
}
}
// todo: switch to nodejs or electron (KT-35327)
// while webpack is not supported in nodejs target, need to override target in webpack.config.d
browser()
}
}

Expand All @@ -34,20 +23,3 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutinesVersion")
implementation("org.jetbrains:kotlin-extensions:$kotlinExtensionsVersion")
}

tasks.named("nodeTest") {
enabled = false
}

val copyResources = task("copyResources") {
copy {
from("src/main/resources")
into("../build/js/packages/projector-launcher-electronapp")
}
}

tasks["compileKotlinJs"].dependsOn(copyResources)

rootProject.plugins.withType<NodeJsRootPlugin> {
rootProject.the<NodeJsRootExtension>().download = false
}
25 changes: 25 additions & 0 deletions projector-launcher/electronapp/src/main/resources/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"main": "electronapp.js",
"devDependencies": {},
"dependencies": {
"electron": "^10.1.2",
"open": "^7.2.1"
},
"scripts": {
"electron": "electron ."
},
"peerDependencies": {},
"optionalDependencies": {},
"bundledDependencies": [],
"keywords": [
"projector",
"jetbrains",
"kotlin",
"kotlin-js"
],
"author": "projector",
"license": "MIT",
"name": "projector-launcher",
"description": "Desktop launcher for Projector, written in Kotlin, Electron and Node",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// todo: remove after https://youtrack.jetbrains.com/issue/KT-35327 is fixed
config.target = 'electron-renderer';

// todo: remove after https://youtrack.jetbrains.com/issue/KT-40159 is fixed
config.output = config.output || {};
config.output.globalObject = "this";
2 changes: 1 addition & 1 deletion projector-launcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "./gradlew build",
"run": "electron build/js/packages/projector-launcher-electronapp",
"gradle-node": "./gradlew -p electronapp nodeRun",
"packager": "electron-packager --executable-name=projector --out=./out --overwrite --icon=./electronapp/src/main/resources/assets/img/electron-icon.ico --all ./build/js/packages/projector-launcher-electronapp projector"
"packager": "electron-packager --executable-name=projector --out=./out --overwrite --icon=./electronapp/src/main/resources/assets/img/electron-icon.ico --all ./electronapp/build/distributions projector"
},
"keywords": [
"projector",
Expand Down

0 comments on commit e4b6b0f

Please sign in to comment.