-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
151 lines (133 loc) · 5.05 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
plugins {
kotlin("js") version "1.6.10"
id("com.github.turansky.kfc.webpack") version "4.63.0"
}
group = "fr.insa"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
fun kotlinw(target: String): String =
"org.jetbrains.kotlin-wrappers:kotlin-$target"
dependencies {
testImplementation(kotlin("test"))
implementation(enforcedPlatform(kotlinw("wrappers-bom:0.0.1-pre.290-kotlin-1.6.10")))
//React
implementation(kotlinw("react"))
implementation(kotlinw("react-dom"))
implementation(kotlinw("react-router-dom"))
//Inline svg
implementation(npm("react-inlinesvg", "2.3.0"))
//Map
implementation(npm("react-leaflet", "3.2.2"))
implementation(npm("leaflet", "1.7.1"))
//Utility dev npm dependencies
implementation(devNpm("zlib", "1.0.5"))
implementation(devNpm("path", "0.12.7"))
implementation(devNpm("postcss", "8.4.5"))
//Code optimizations
implementation(devNpm("terser-webpack-plugin", "5.3.0"))
implementation(devNpm("compression-webpack-plugin", "9.2.0"))
implementation(devNpm("@gfx/zopfli", "1.0.15"))
//SAAS
implementation(devNpm("sass", "1.45.2"))
implementation(devNpm("sass-loader", "12.4.0"))
implementation(devNpm("postcss-loader", "6.2.1"))
implementation(devNpm("autoprefixer", "10.4.1"))
}
kotlin {
js(IR) {
binaries.executable()
browser {
commonWebpackConfig {
cssSupport.enabled = true
val devServerPort: String? by project
devServer = org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.DevServer(
port = devServerPort?.toIntOrNull() ?: 3000,
static = mutableListOf("$buildDir/processedResources/js/main")
)
}
//Dev task
runTask {
sourceMaps = true
}
}
}
}
tasks {
patchWebpackConfig {
// language=JavaScript
patch(
"""
const TerserPlugin = require('terser-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const {gzip} = require('@gfx/zopfli');
const zlib = require('zlib');
const autoprefixer = require('autoprefixer');
const webpack = require('webpack')
if (config.mode === "production") {
console.info("=====> Compressing and minifying <=====");
config.optimization = {
minimize: true,
minimizer: [new TerserPlugin()],
};
config.plugins = [
new CompressionPlugin({
filename: '[path][base].br',
algorithm: 'brotliCompress',
test: /\.(js|css|html|svg)${'$'}/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
threshold: 10240,
minRatio: 0.8
}),
new CompressionPlugin({
test: /\.(js|css|html|svg)${'$'}/,
filename: '[path][base].gz',
algorithm: gzip,
threshold: 10240,
minRatio: 0.8
})];
}
config.module.rules.push({
test: /\.s[ac]ss${'$'}/i,
use: [
//Creates `style` nodes from JS strings
'style-loader',
//Translates CSS into CommonJS
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
//Improves styles with post processing
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [autoprefixer()]
//TODO MIGRATE FROM SASS TO ONLY POSTCSS (https://simonecorsi.medium.com/moving-from-sass-to-postcss-why-what-and-how-f68b1bc760dc)
//TODO EXPLORE THE POSSIBILITIES AT https://github.com/postcss/postcss#plugins
}
}
},
//Compiles Sass to CSS
'sass-loader',
],
});
config.plugins.push(new webpack.ProvidePlugin({
process: 'process/browser',
}));
config.output.publicPath = '/';
if (config.devServer) {
config.devServer.historyApiFallback = true;
}
config.resolve.modules.push("processedResources/js/main");
""".trimIndent()
)
}
}