@botonic/example-blank 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/rspack.config.ts +383 -0
- package/tsconfig.json +8 -0
- package/babel.config.js +0 -29
- package/webpack.config.js +0 -338
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/example-blank",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"build": "
|
|
6
|
-
"start": "
|
|
5
|
+
"build": "ENVIRONMENT=production NODE_ENV=production rspack build --env target=all --mode=production",
|
|
6
|
+
"start": "ENVIRONMENT=local NODE_ENV=development rspack serve --env target=dev --mode=development",
|
|
7
7
|
"deploy": "botonic deploy -c build",
|
|
8
8
|
"test": "jest"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@babel/runtime": "^7.
|
|
12
|
-
"@botonic/react": "^0.
|
|
11
|
+
"@babel/runtime": "^7.26.0",
|
|
12
|
+
"@botonic/react": "^0.31.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@botonic/dx": "^0.
|
|
15
|
+
"@botonic/dx": "^0.31.1"
|
|
16
16
|
},
|
|
17
17
|
"engines": {
|
|
18
18
|
"node": ">=20.0.0"
|
package/rspack.config.ts
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { Configuration } from '@rspack/cli'
|
|
2
|
+
import * as rspack from '@rspack/core'
|
|
3
|
+
import ReactRefreshPlugin from '@rspack/plugin-react-refresh'
|
|
4
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
5
|
+
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin'
|
|
6
|
+
import path from 'path'
|
|
7
|
+
|
|
8
|
+
const ROOT_PATH = path.resolve(__dirname, 'src')
|
|
9
|
+
const OUTPUT_PATH = path.resolve(__dirname, 'dist')
|
|
10
|
+
const NODE_MODULES_PATH = path.resolve(__dirname, 'node_modules')
|
|
11
|
+
const WEBVIEWS_PATH = path.resolve(OUTPUT_PATH, 'webviews')
|
|
12
|
+
const BOTONIC_PATH = path.resolve(NODE_MODULES_PATH, '@botonic', 'react')
|
|
13
|
+
|
|
14
|
+
enum BotonicTarget {
|
|
15
|
+
ALL = 'all',
|
|
16
|
+
DEV = 'dev',
|
|
17
|
+
NODE = 'node',
|
|
18
|
+
WEBVIEWS = 'webviews',
|
|
19
|
+
WEBCHAT = 'webchat',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const WEBPACK_ENTRIES_DIRNAME = 'webpack-entries'
|
|
23
|
+
const WEBPACK_ENTRIES = {
|
|
24
|
+
DEV: 'dev-entry.js',
|
|
25
|
+
NODE: 'node-entry.js',
|
|
26
|
+
WEBCHAT: 'webchat-entry.js',
|
|
27
|
+
WEBVIEWS: 'webviews-entry.js',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const TEMPLATES = {
|
|
31
|
+
WEBCHAT: 'webchat.template.html',
|
|
32
|
+
WEBVIEWS: 'webview.template.html',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const UMD_LIBRARY_TARGET = 'umd'
|
|
36
|
+
|
|
37
|
+
const LIBRARY_NAME = {
|
|
38
|
+
BOTONIC: 'Botonic',
|
|
39
|
+
WEBVIEW: 'BotonicWebview',
|
|
40
|
+
BOT: 'bot',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const FILENAME = {
|
|
44
|
+
WEBCHAT: 'webchat.botonic.js',
|
|
45
|
+
WEBVIEWS: 'webviews.js',
|
|
46
|
+
BOT: 'bot.js',
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
enum Mode {
|
|
50
|
+
development = 'development',
|
|
51
|
+
production = 'production',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const HUBTYPE_DEFAULTS = {
|
|
55
|
+
API_URL: 'https://api.hubtype.com',
|
|
56
|
+
WEBCHAT_PUSHER_KEY: '434ca667c8e6cb3f641c', // pragma: allowlist secret
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const CONFIG_ENVIRONMENTS = ['production', 'staging', 'local']
|
|
60
|
+
|
|
61
|
+
const resolveConfig = {
|
|
62
|
+
extensions: ['.*', '.js', '.jsx', '.ts', '.tsx'],
|
|
63
|
+
alias: {
|
|
64
|
+
BotonicProject: ROOT_PATH,
|
|
65
|
+
react: path.resolve('./node_modules/react'),
|
|
66
|
+
// 'styled-components': path.resolve('./node_modules/styled-components'),
|
|
67
|
+
'@botonic/react': BOTONIC_PATH,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const isDev = String(process.env.ENVIRONMENT) === 'local'
|
|
72
|
+
|
|
73
|
+
const typescriptLoaderConfig = [
|
|
74
|
+
{
|
|
75
|
+
test: /\.tsx?$/,
|
|
76
|
+
exclude: [/node_modules/],
|
|
77
|
+
use: {
|
|
78
|
+
loader: 'builtin:swc-loader',
|
|
79
|
+
options: {
|
|
80
|
+
jsc: {
|
|
81
|
+
parser: {
|
|
82
|
+
syntax: 'typescript',
|
|
83
|
+
tsx: true,
|
|
84
|
+
},
|
|
85
|
+
transform: {
|
|
86
|
+
react: {
|
|
87
|
+
runtime: 'automatic',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
keepClassNames: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
type: 'javascript/auto',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
test: /\.jsx?$/,
|
|
98
|
+
exclude: [/node_modules/],
|
|
99
|
+
use: {
|
|
100
|
+
loader: 'builtin:swc-loader',
|
|
101
|
+
options: {
|
|
102
|
+
jsc: {
|
|
103
|
+
parser: {
|
|
104
|
+
syntax: 'ecmascript',
|
|
105
|
+
jsx: true,
|
|
106
|
+
},
|
|
107
|
+
transform: {
|
|
108
|
+
react: {
|
|
109
|
+
pragma: 'React.createElement',
|
|
110
|
+
pragmaFrag: 'React.Fragment',
|
|
111
|
+
throwIfNamespace: true,
|
|
112
|
+
development: isDev,
|
|
113
|
+
refresh: isDev,
|
|
114
|
+
useBuiltins: false,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
keepClassNames: true,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
type: 'javascript/auto',
|
|
122
|
+
},
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
const fileLoaderConfig = [
|
|
126
|
+
{
|
|
127
|
+
test: /\.(png|jpe?g|gif|svg)$/i,
|
|
128
|
+
type: 'asset/resource',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
test: /^BUILD_ID$/,
|
|
132
|
+
type: 'asset/source',
|
|
133
|
+
},
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
const nullLoaderConfig = {
|
|
137
|
+
test: /\.(scss|css)$/,
|
|
138
|
+
use: 'null-loader',
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const stylesLoaderConfig = [
|
|
142
|
+
{
|
|
143
|
+
test: /\.(sass|scss|css)$/,
|
|
144
|
+
use: ['style-loader', 'css-loader', 'sass-loader'],
|
|
145
|
+
type: 'javascript/auto',
|
|
146
|
+
},
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
function log(message: string) {
|
|
150
|
+
// using errors to avoid screwing up rspack-bundle-analyzer when running with --profile
|
|
151
|
+
console.error(message)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function getHtmlWebpackPlugin(templateName: string) {
|
|
155
|
+
return new HtmlWebpackPlugin({
|
|
156
|
+
template: path.resolve(BOTONIC_PATH, 'src', templateName),
|
|
157
|
+
filename: 'index.html',
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function getConfigEnvironment() {
|
|
162
|
+
const configEnvironment = String(process.env.ENVIRONMENT).toLowerCase()
|
|
163
|
+
if (!CONFIG_ENVIRONMENTS.includes(configEnvironment)) {
|
|
164
|
+
console.error(
|
|
165
|
+
`You need to set env var ENVIRONMENT to one of these: ${CONFIG_ENVIRONMENTS}. Current value: ${configEnvironment}`
|
|
166
|
+
)
|
|
167
|
+
// eslint-disable-next-line no-process-exit
|
|
168
|
+
process.exit(1)
|
|
169
|
+
}
|
|
170
|
+
return configEnvironment
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function getPlugins(mode: string, target: string) {
|
|
174
|
+
const environment = getConfigEnvironment()
|
|
175
|
+
log(
|
|
176
|
+
`Generating bundle for: ${target}\nRspack running on mode '${mode}' with env var ENVIRONMENT set to: ${environment}`
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
const plugins = [
|
|
180
|
+
new rspack.EnvironmentPlugin({
|
|
181
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
182
|
+
HUBTYPE_API_URL: process.env.HUBTYPE_API_URL || HUBTYPE_DEFAULTS.API_URL,
|
|
183
|
+
BOTONIC_TARGET: BotonicTarget.NODE,
|
|
184
|
+
WEBCHAT_PUSHER_KEY:
|
|
185
|
+
process.env.WEBCHAT_PUSHER_KEY || HUBTYPE_DEFAULTS.WEBCHAT_PUSHER_KEY,
|
|
186
|
+
ENVIRONMENT: process.env.ENVIRONMENT,
|
|
187
|
+
}),
|
|
188
|
+
new rspack.ProgressPlugin(),
|
|
189
|
+
]
|
|
190
|
+
|
|
191
|
+
if (isDev) {
|
|
192
|
+
// @ts-ignore
|
|
193
|
+
plugins.push(new ReactRefreshPlugin())
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return plugins
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function sourceMap(mode: string) {
|
|
200
|
+
if (mode === Mode.production) {
|
|
201
|
+
return 'hidden-source-map'
|
|
202
|
+
} else if (mode === Mode.development) {
|
|
203
|
+
return 'eval-cheap-source-map'
|
|
204
|
+
} else {
|
|
205
|
+
throw new Error(
|
|
206
|
+
'Invalid mode argument (' + mode + '). See package.json scripts'
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Not work for Webviews, not keep fnames
|
|
212
|
+
const minimizerPlugin = new rspack.SwcJsMinimizerRspackPlugin({
|
|
213
|
+
minimizerOptions: {
|
|
214
|
+
minify: true,
|
|
215
|
+
compress: {
|
|
216
|
+
keep_classnames: true,
|
|
217
|
+
keep_fargs: false,
|
|
218
|
+
keep_fnames: true,
|
|
219
|
+
},
|
|
220
|
+
mangle: {
|
|
221
|
+
keep_fnames: true,
|
|
222
|
+
keep_classnames: true,
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
function botonicDevConfig(mode: Mode): Configuration {
|
|
228
|
+
return {
|
|
229
|
+
optimization: {
|
|
230
|
+
minimize: false,
|
|
231
|
+
},
|
|
232
|
+
mode,
|
|
233
|
+
devtool: sourceMap(mode),
|
|
234
|
+
target: 'web',
|
|
235
|
+
entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.DEV),
|
|
236
|
+
module: {
|
|
237
|
+
rules: [
|
|
238
|
+
...typescriptLoaderConfig,
|
|
239
|
+
...fileLoaderConfig,
|
|
240
|
+
...stylesLoaderConfig,
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
output: {
|
|
244
|
+
path: OUTPUT_PATH,
|
|
245
|
+
filename: FILENAME.WEBCHAT,
|
|
246
|
+
library: LIBRARY_NAME.BOTONIC,
|
|
247
|
+
libraryTarget: UMD_LIBRARY_TARGET,
|
|
248
|
+
libraryExport: 'app',
|
|
249
|
+
assetModuleFilename: 'assets/[hash][ext][query]',
|
|
250
|
+
},
|
|
251
|
+
resolve: resolveConfig,
|
|
252
|
+
devServer: {
|
|
253
|
+
static: [OUTPUT_PATH],
|
|
254
|
+
liveReload: true,
|
|
255
|
+
historyApiFallback: true,
|
|
256
|
+
hot: true,
|
|
257
|
+
},
|
|
258
|
+
plugins: [
|
|
259
|
+
getHtmlWebpackPlugin(TEMPLATES.WEBCHAT),
|
|
260
|
+
new NodePolyfillPlugin({ onlyAliases: ['stream'] }),
|
|
261
|
+
new rspack.NormalModuleReplacementPlugin(/node:stream/, resource => {
|
|
262
|
+
resource.request = resource.request.replace(/^node:/, '')
|
|
263
|
+
}),
|
|
264
|
+
...getPlugins(mode, BotonicTarget.DEV),
|
|
265
|
+
],
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function botonicWebchatConfig(mode: Mode): Configuration {
|
|
270
|
+
return {
|
|
271
|
+
optimization: {
|
|
272
|
+
minimize: true,
|
|
273
|
+
minimizer: [minimizerPlugin],
|
|
274
|
+
},
|
|
275
|
+
mode,
|
|
276
|
+
devtool: sourceMap(mode),
|
|
277
|
+
target: 'web',
|
|
278
|
+
entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.WEBCHAT),
|
|
279
|
+
output: {
|
|
280
|
+
path: OUTPUT_PATH,
|
|
281
|
+
filename: FILENAME.WEBCHAT,
|
|
282
|
+
library: LIBRARY_NAME.BOTONIC,
|
|
283
|
+
libraryTarget: UMD_LIBRARY_TARGET,
|
|
284
|
+
libraryExport: 'app',
|
|
285
|
+
assetModuleFilename: 'assets/[hash][ext][query]',
|
|
286
|
+
},
|
|
287
|
+
module: {
|
|
288
|
+
rules: [
|
|
289
|
+
...typescriptLoaderConfig,
|
|
290
|
+
...fileLoaderConfig,
|
|
291
|
+
...stylesLoaderConfig,
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
resolve: resolveConfig,
|
|
295
|
+
plugins: [
|
|
296
|
+
getHtmlWebpackPlugin(TEMPLATES.WEBCHAT),
|
|
297
|
+
...getPlugins(mode, BotonicTarget.WEBCHAT),
|
|
298
|
+
],
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function botonicWebviewsConfig(mode: Mode): Configuration {
|
|
303
|
+
return {
|
|
304
|
+
optimization: {
|
|
305
|
+
sideEffects: true, // critical so that tree-shaking discards browser code from @botonic/react
|
|
306
|
+
usedExports: true,
|
|
307
|
+
minimize: true,
|
|
308
|
+
minimizer: mode === Mode.production ? [minimizerPlugin] : [],
|
|
309
|
+
},
|
|
310
|
+
mode,
|
|
311
|
+
devtool: sourceMap(mode),
|
|
312
|
+
target: 'web',
|
|
313
|
+
entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.WEBVIEWS),
|
|
314
|
+
output: {
|
|
315
|
+
path: WEBVIEWS_PATH,
|
|
316
|
+
filename: FILENAME.WEBVIEWS,
|
|
317
|
+
library: LIBRARY_NAME.WEBVIEW,
|
|
318
|
+
libraryTarget: UMD_LIBRARY_TARGET,
|
|
319
|
+
libraryExport: 'app',
|
|
320
|
+
assetModuleFilename: '../assets/[hash][ext][query]',
|
|
321
|
+
},
|
|
322
|
+
module: {
|
|
323
|
+
rules: [
|
|
324
|
+
...typescriptLoaderConfig,
|
|
325
|
+
...fileLoaderConfig,
|
|
326
|
+
...stylesLoaderConfig,
|
|
327
|
+
],
|
|
328
|
+
},
|
|
329
|
+
resolve: resolveConfig,
|
|
330
|
+
plugins: [
|
|
331
|
+
getHtmlWebpackPlugin(TEMPLATES.WEBVIEWS),
|
|
332
|
+
...getPlugins(mode, BotonicTarget.WEBVIEWS),
|
|
333
|
+
],
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function botonicServerConfig(mode: string): Configuration {
|
|
338
|
+
return {
|
|
339
|
+
optimization: {
|
|
340
|
+
sideEffects: true, // critical so that tree-shaking discards browser code from @botonic/react
|
|
341
|
+
minimize: true,
|
|
342
|
+
minimizer: mode === Mode.production ? [minimizerPlugin] : [],
|
|
343
|
+
},
|
|
344
|
+
context: ROOT_PATH,
|
|
345
|
+
// 'mode' removed so that we're forced to be explicit
|
|
346
|
+
target: 'node',
|
|
347
|
+
entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.NODE),
|
|
348
|
+
output: {
|
|
349
|
+
filename: FILENAME.BOT,
|
|
350
|
+
library: LIBRARY_NAME.BOT,
|
|
351
|
+
libraryTarget: 'umd',
|
|
352
|
+
libraryExport: 'app',
|
|
353
|
+
assetModuleFilename: 'assets/[hash][ext][query]',
|
|
354
|
+
},
|
|
355
|
+
module: {
|
|
356
|
+
rules: [...typescriptLoaderConfig, ...fileLoaderConfig, nullLoaderConfig],
|
|
357
|
+
},
|
|
358
|
+
resolve: resolveConfig,
|
|
359
|
+
plugins: getPlugins(mode, BotonicTarget.NODE),
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export default function (
|
|
364
|
+
env: { target: string },
|
|
365
|
+
argv: { mode: Mode }
|
|
366
|
+
): Configuration[] {
|
|
367
|
+
if (env.target === BotonicTarget.ALL) {
|
|
368
|
+
return [
|
|
369
|
+
botonicServerConfig(argv.mode),
|
|
370
|
+
botonicWebviewsConfig(argv.mode),
|
|
371
|
+
botonicWebchatConfig(argv.mode),
|
|
372
|
+
]
|
|
373
|
+
} else if (env.target === BotonicTarget.DEV) {
|
|
374
|
+
return [botonicDevConfig(argv.mode)]
|
|
375
|
+
} else if (env.target === BotonicTarget.NODE) {
|
|
376
|
+
return [botonicServerConfig(argv.mode)]
|
|
377
|
+
} else if (env.target === BotonicTarget.WEBVIEWS) {
|
|
378
|
+
return [botonicWebviewsConfig(argv.mode)]
|
|
379
|
+
} else if (env.target === BotonicTarget.WEBCHAT) {
|
|
380
|
+
return [botonicWebchatConfig(argv.mode)]
|
|
381
|
+
}
|
|
382
|
+
throw new Error(`Invalid target ${env.target}`)
|
|
383
|
+
}
|
package/tsconfig.json
ADDED
package/babel.config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This babel configuration is used along with Jest for execute tests,
|
|
3
|
-
* do not modify to avoid conflicts with webpack.config.js.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
presets: [
|
|
8
|
-
[
|
|
9
|
-
'@babel/preset-env',
|
|
10
|
-
{
|
|
11
|
-
targets: {
|
|
12
|
-
node: 'current',
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
[
|
|
17
|
-
'@babel/react',
|
|
18
|
-
{
|
|
19
|
-
targets: {
|
|
20
|
-
node: 'current',
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
],
|
|
25
|
-
plugins: [
|
|
26
|
-
require('@babel/plugin-transform-modules-commonjs'),
|
|
27
|
-
require('@babel/plugin-transform-runtime'),
|
|
28
|
-
],
|
|
29
|
-
}
|
package/webpack.config.js
DELETED
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const webpack = require('webpack')
|
|
3
|
-
const TerserPlugin = require('terser-webpack-plugin')
|
|
4
|
-
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
5
|
-
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
|
|
6
|
-
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin')
|
|
7
|
-
|
|
8
|
-
const ROOT = path.resolve(__dirname, 'src')
|
|
9
|
-
const ASSETS_DIRNAME = 'assets'
|
|
10
|
-
|
|
11
|
-
const OUTPUT_PATH = path.resolve(__dirname, 'dist')
|
|
12
|
-
const WEBVIEWS_PATH = path.resolve(OUTPUT_PATH, 'webviews')
|
|
13
|
-
|
|
14
|
-
const BOTONIC_PATH = path.resolve(
|
|
15
|
-
__dirname,
|
|
16
|
-
'node_modules',
|
|
17
|
-
'@botonic',
|
|
18
|
-
'react'
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
const WEBPACK_MODE = {
|
|
22
|
-
DEVELOPMENT: 'development',
|
|
23
|
-
PRODUCTION: 'production',
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const BOTONIC_TARGETS = {
|
|
27
|
-
ALL: 'all',
|
|
28
|
-
DEV: 'dev',
|
|
29
|
-
NODE: 'node',
|
|
30
|
-
WEBVIEWS: 'webviews',
|
|
31
|
-
WEBCHAT: 'webchat',
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const WEBPACK_ENTRIES_DIRNAME = 'webpack-entries'
|
|
35
|
-
const WEBPACK_ENTRIES = {
|
|
36
|
-
DEV: 'dev-entry.js',
|
|
37
|
-
NODE: 'node-entry.js',
|
|
38
|
-
WEBCHAT: 'webchat-entry.js',
|
|
39
|
-
WEBVIEWS: 'webviews-entry.js',
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const TEMPLATES = {
|
|
43
|
-
WEBCHAT: 'webchat.template.html',
|
|
44
|
-
WEBVIEWS: 'webview.template.html',
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const UMD_LIBRARY_TARGET = 'umd'
|
|
48
|
-
const BOTONIC_LIBRARY_NAME = 'Botonic'
|
|
49
|
-
const WEBCHAT_FILENAME = 'webchat.botonic.js'
|
|
50
|
-
|
|
51
|
-
function sourceMap(mode) {
|
|
52
|
-
if (mode === WEBPACK_MODE.PRODUCTION) return 'hidden-source-map'
|
|
53
|
-
else if (mode === WEBPACK_MODE.DEVELOPMENT) return 'eval-cheap-source-map'
|
|
54
|
-
else
|
|
55
|
-
throw new Error(
|
|
56
|
-
'Invalid mode argument (' + mode + '). See package.json scripts'
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const optimizationConfig = {
|
|
61
|
-
minimize: true,
|
|
62
|
-
minimizer: [
|
|
63
|
-
new TerserPlugin({
|
|
64
|
-
parallel: true,
|
|
65
|
-
terserOptions: {
|
|
66
|
-
keep_fnames: true,
|
|
67
|
-
},
|
|
68
|
-
}),
|
|
69
|
-
],
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const resolveConfig = {
|
|
73
|
-
extensions: ['*', '.js', '.jsx', '.ts', '.tsx', '.mjs'],
|
|
74
|
-
alias: {
|
|
75
|
-
react: path.resolve(__dirname, 'node_modules', 'react'),
|
|
76
|
-
'styled-components': path.resolve(
|
|
77
|
-
__dirname,
|
|
78
|
-
'node_modules',
|
|
79
|
-
'styled-components'
|
|
80
|
-
),
|
|
81
|
-
},
|
|
82
|
-
fallback: {
|
|
83
|
-
util: require.resolve('util'),
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const babelLoaderConfig = {
|
|
88
|
-
test: /\.(js|jsx|ts|tsx|mjs)$/,
|
|
89
|
-
exclude: /node_modules\/(?!@botonic)/,
|
|
90
|
-
use: {
|
|
91
|
-
loader: 'babel-loader',
|
|
92
|
-
options: {
|
|
93
|
-
sourceType: 'unambiguous',
|
|
94
|
-
cacheDirectory: true,
|
|
95
|
-
presets: [
|
|
96
|
-
'@babel/react',
|
|
97
|
-
[
|
|
98
|
-
'@babel/preset-env',
|
|
99
|
-
{
|
|
100
|
-
modules: false,
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
],
|
|
104
|
-
plugins: [
|
|
105
|
-
'@babel/plugin-transform-runtime',
|
|
106
|
-
],
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function fileLoaderConfig(outputPath) {
|
|
112
|
-
return {
|
|
113
|
-
test: /\.(jpe?g|png|gif|svg)$/i,
|
|
114
|
-
use: [
|
|
115
|
-
{
|
|
116
|
-
loader: 'file-loader',
|
|
117
|
-
options: {
|
|
118
|
-
outputPath: outputPath,
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const nullLoaderConfig = {
|
|
126
|
-
test: /\.(scss|css)$/,
|
|
127
|
-
use: 'null-loader',
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const stylesLoaderConfig = {
|
|
131
|
-
test: /\.(scss|css)$/,
|
|
132
|
-
use: [
|
|
133
|
-
{
|
|
134
|
-
loader: 'style-loader',
|
|
135
|
-
options: {
|
|
136
|
-
insert: function (element) {
|
|
137
|
-
if (!window._botonicInsertStyles) window._botonicInsertStyles = []
|
|
138
|
-
window._botonicInsertStyles.push(element)
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
'css-loader',
|
|
143
|
-
'sass-loader',
|
|
144
|
-
],
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const imageminPlugin = new ImageMinimizerPlugin({
|
|
148
|
-
minimizer: {
|
|
149
|
-
implementation: ImageMinimizerPlugin.imageminMinify,
|
|
150
|
-
options: {
|
|
151
|
-
plugins: [
|
|
152
|
-
"imagemin-gifsicle",
|
|
153
|
-
"imagemin-jpegtran",
|
|
154
|
-
"imagemin-optipng",
|
|
155
|
-
"imagemin-svgo",
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
function botonicDevConfig(mode) {
|
|
162
|
-
return {
|
|
163
|
-
mode: mode,
|
|
164
|
-
devtool: sourceMap(mode),
|
|
165
|
-
entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.DEV),
|
|
166
|
-
target: 'web',
|
|
167
|
-
module: {
|
|
168
|
-
rules: [
|
|
169
|
-
babelLoaderConfig,
|
|
170
|
-
fileLoaderConfig(ASSETS_DIRNAME),
|
|
171
|
-
stylesLoaderConfig,
|
|
172
|
-
],
|
|
173
|
-
},
|
|
174
|
-
output: {
|
|
175
|
-
filename: WEBCHAT_FILENAME,
|
|
176
|
-
library: BOTONIC_LIBRARY_NAME,
|
|
177
|
-
libraryTarget: UMD_LIBRARY_TARGET,
|
|
178
|
-
libraryExport: 'app',
|
|
179
|
-
path: OUTPUT_PATH,
|
|
180
|
-
},
|
|
181
|
-
resolve: resolveConfig,
|
|
182
|
-
devServer: {
|
|
183
|
-
static: [OUTPUT_PATH],
|
|
184
|
-
liveReload: true,
|
|
185
|
-
historyApiFallback: true,
|
|
186
|
-
hot: true,
|
|
187
|
-
},
|
|
188
|
-
plugins: [
|
|
189
|
-
new HtmlWebpackPlugin({
|
|
190
|
-
template: path.resolve(BOTONIC_PATH, 'src', TEMPLATES.WEBCHAT),
|
|
191
|
-
filename: 'index.html',
|
|
192
|
-
}),
|
|
193
|
-
new webpack.HotModuleReplacementPlugin(),
|
|
194
|
-
imageminPlugin,
|
|
195
|
-
new webpack.DefinePlugin({
|
|
196
|
-
IS_BROWSER: true,
|
|
197
|
-
IS_NODE: false,
|
|
198
|
-
HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL),
|
|
199
|
-
...(mode === 'development'
|
|
200
|
-
? { MODELS_BASE_URL: JSON.stringify('http://localhost:8080') }
|
|
201
|
-
: {}),
|
|
202
|
-
}),
|
|
203
|
-
new webpack.ProvidePlugin({
|
|
204
|
-
process: 'process/browser',
|
|
205
|
-
}),
|
|
206
|
-
],
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function botonicWebchatConfig(mode) {
|
|
211
|
-
return {
|
|
212
|
-
optimization: optimizationConfig,
|
|
213
|
-
mode: mode,
|
|
214
|
-
devtool: sourceMap(mode),
|
|
215
|
-
target: 'web',
|
|
216
|
-
entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.WEBCHAT),
|
|
217
|
-
module: {
|
|
218
|
-
rules: [
|
|
219
|
-
babelLoaderConfig,
|
|
220
|
-
fileLoaderConfig(ASSETS_DIRNAME),
|
|
221
|
-
stylesLoaderConfig,
|
|
222
|
-
],
|
|
223
|
-
},
|
|
224
|
-
output: {
|
|
225
|
-
filename: WEBCHAT_FILENAME,
|
|
226
|
-
library: BOTONIC_LIBRARY_NAME,
|
|
227
|
-
libraryTarget: UMD_LIBRARY_TARGET,
|
|
228
|
-
libraryExport: 'app',
|
|
229
|
-
path: OUTPUT_PATH,
|
|
230
|
-
},
|
|
231
|
-
resolve: resolveConfig,
|
|
232
|
-
plugins: [
|
|
233
|
-
new HtmlWebpackPlugin({
|
|
234
|
-
template: path.resolve(BOTONIC_PATH, 'src', TEMPLATES.WEBCHAT),
|
|
235
|
-
filename: 'index.html',
|
|
236
|
-
}),
|
|
237
|
-
imageminPlugin,
|
|
238
|
-
new webpack.DefinePlugin({
|
|
239
|
-
IS_BROWSER: true,
|
|
240
|
-
IS_NODE: false,
|
|
241
|
-
HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL),
|
|
242
|
-
WEBCHAT_PUSHER_KEY: JSON.stringify(process.env.WEBCHAT_PUSHER_KEY),
|
|
243
|
-
}),
|
|
244
|
-
],
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function botonicWebviewsConfig(mode) {
|
|
249
|
-
return {
|
|
250
|
-
optimization: optimizationConfig,
|
|
251
|
-
mode: mode,
|
|
252
|
-
devtool: sourceMap(mode),
|
|
253
|
-
target: 'web',
|
|
254
|
-
entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.WEBVIEWS),
|
|
255
|
-
output: {
|
|
256
|
-
filename: 'webviews.js',
|
|
257
|
-
library: 'BotonicWebview',
|
|
258
|
-
libraryTarget: UMD_LIBRARY_TARGET,
|
|
259
|
-
libraryExport: 'app',
|
|
260
|
-
path: WEBVIEWS_PATH,
|
|
261
|
-
},
|
|
262
|
-
module: {
|
|
263
|
-
rules: [
|
|
264
|
-
babelLoaderConfig,
|
|
265
|
-
fileLoaderConfig(path.join('..', ASSETS_DIRNAME)),
|
|
266
|
-
stylesLoaderConfig,
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
resolve: resolveConfig,
|
|
270
|
-
plugins: [
|
|
271
|
-
new HtmlWebpackPlugin({
|
|
272
|
-
template: path.resolve(BOTONIC_PATH, 'src', TEMPLATES.WEBVIEWS),
|
|
273
|
-
filename: 'index.html',
|
|
274
|
-
}),
|
|
275
|
-
imageminPlugin,
|
|
276
|
-
new webpack.DefinePlugin({
|
|
277
|
-
IS_BROWSER: true,
|
|
278
|
-
IS_NODE: false,
|
|
279
|
-
HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL),
|
|
280
|
-
}),
|
|
281
|
-
],
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function botonicNodeConfig(mode) {
|
|
286
|
-
return {
|
|
287
|
-
context: ROOT,
|
|
288
|
-
optimization: optimizationConfig,
|
|
289
|
-
mode: mode,
|
|
290
|
-
devtool: sourceMap(mode),
|
|
291
|
-
target: 'node',
|
|
292
|
-
entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.NODE),
|
|
293
|
-
resolve: resolveConfig,
|
|
294
|
-
output: {
|
|
295
|
-
filename: 'bot.js',
|
|
296
|
-
library: 'bot',
|
|
297
|
-
libraryTarget: UMD_LIBRARY_TARGET,
|
|
298
|
-
libraryExport: 'app',
|
|
299
|
-
path: OUTPUT_PATH,
|
|
300
|
-
},
|
|
301
|
-
module: {
|
|
302
|
-
rules: [
|
|
303
|
-
babelLoaderConfig,
|
|
304
|
-
fileLoaderConfig(ASSETS_DIRNAME),
|
|
305
|
-
nullLoaderConfig,
|
|
306
|
-
],
|
|
307
|
-
},
|
|
308
|
-
plugins: [
|
|
309
|
-
new CleanWebpackPlugin({ cleanOnceBeforeBuildPatterns: ['dist'] }),
|
|
310
|
-
imageminPlugin,
|
|
311
|
-
new webpack.DefinePlugin({
|
|
312
|
-
IS_BROWSER: false,
|
|
313
|
-
IS_NODE: true,
|
|
314
|
-
HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL),
|
|
315
|
-
}),
|
|
316
|
-
],
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
module.exports = function (env, argv) {
|
|
321
|
-
if (env.target === BOTONIC_TARGETS.ALL) {
|
|
322
|
-
return [
|
|
323
|
-
botonicNodeConfig(argv.mode),
|
|
324
|
-
botonicWebviewsConfig(argv.mode),
|
|
325
|
-
botonicWebchatConfig(argv.mode),
|
|
326
|
-
]
|
|
327
|
-
} else if (env.target === BOTONIC_TARGETS.DEV) {
|
|
328
|
-
return [botonicDevConfig(argv.mode)]
|
|
329
|
-
} else if (env.target === BOTONIC_TARGETS.NODE) {
|
|
330
|
-
return [botonicNodeConfig(argv.mode)]
|
|
331
|
-
} else if (env.target === BOTONIC_TARGETS.WEBVIEWS) {
|
|
332
|
-
return [botonicWebviewsConfig(argv.mode)]
|
|
333
|
-
} else if (env.target === BOTONIC_TARGETS.WEBCHAT) {
|
|
334
|
-
return [botonicWebchatConfig(argv.mode)]
|
|
335
|
-
} else {
|
|
336
|
-
return null
|
|
337
|
-
}
|
|
338
|
-
}
|