@raisenow/tamaro-cli 1.0.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/.eslintignore +2 -0
- package/.eslintrc.js +53 -0
- package/.gitignore +13 -0
- package/.nvmrc +1 -0
- package/.prettierignore +2 -0
- package/.prettierrc.js +18 -0
- package/bin/cli +4 -0
- package/package.json +101 -0
- package/src/InterpolateHtmlPlugin.ts +43 -0
- package/src/assets/rnw-logo.jpg +0 -0
- package/src/cli.ts +57 -0
- package/src/commands/build/index.ts +22 -0
- package/src/commands/dev/index.ts +10 -0
- package/src/lib/helpers.ts +42 -0
- package/src/polyfills.js +8 -0
- package/src/webpack.config.ts +641 -0
- package/tsconfig.json +76 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const {resolve} = require('path')
|
|
3
|
+
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
root: true,
|
|
8
|
+
env: {
|
|
9
|
+
browser: true,
|
|
10
|
+
node: true,
|
|
11
|
+
es2021: true,
|
|
12
|
+
},
|
|
13
|
+
parserOptions: {
|
|
14
|
+
ecmaFeatures: {
|
|
15
|
+
jsx: true,
|
|
16
|
+
},
|
|
17
|
+
ecmaVersion: 2021,
|
|
18
|
+
sourceType: 'module',
|
|
19
|
+
},
|
|
20
|
+
extends: [
|
|
21
|
+
'eslint:recommended',
|
|
22
|
+
'plugin:node/recommended',
|
|
23
|
+
'plugin:promise/recommended',
|
|
24
|
+
// 'plugin:unicorn/recommended',
|
|
25
|
+
'plugin:@typescript-eslint/recommended',
|
|
26
|
+
'plugin:prettier/recommended',
|
|
27
|
+
],
|
|
28
|
+
plugins: [],
|
|
29
|
+
rules: {
|
|
30
|
+
curly: 1,
|
|
31
|
+
|
|
32
|
+
'node/no-unsupported-features/es-syntax': 0,
|
|
33
|
+
'node/no-missing-import': 0,
|
|
34
|
+
'no-process-exit': 0,
|
|
35
|
+
|
|
36
|
+
'@typescript-eslint/ban-ts-comment': 0,
|
|
37
|
+
'@typescript-eslint/no-explicit-any': 0,
|
|
38
|
+
'@typescript-eslint/no-non-null-assertion': 0,
|
|
39
|
+
'@typescript-eslint/prefer-optional-chain': 1,
|
|
40
|
+
|
|
41
|
+
'prettier/prettier': 1,
|
|
42
|
+
'arrow-body-style': 0,
|
|
43
|
+
'prefer-arrow-callback': 0,
|
|
44
|
+
},
|
|
45
|
+
overrides: [
|
|
46
|
+
{
|
|
47
|
+
files: ['*.ts', '*.tsx'],
|
|
48
|
+
parserOptions: {
|
|
49
|
+
project: resolve(__dirname, 'tsconfig.json'),
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
}
|
package/.gitignore
ADDED
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
14.18.1
|
package/.prettierignore
ADDED
package/.prettierrc.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
printWidth: 80,
|
|
3
|
+
tabWidth: 2,
|
|
4
|
+
useTabs: false,
|
|
5
|
+
semi: false,
|
|
6
|
+
singleQuote: true,
|
|
7
|
+
quoteProps: 'as-needed',
|
|
8
|
+
jsxSingleQuote: false,
|
|
9
|
+
trailingComma: 'all',
|
|
10
|
+
bracketSpacing: false,
|
|
11
|
+
bracketSameLine: false,
|
|
12
|
+
arrowParens: 'always',
|
|
13
|
+
requirePragma: false,
|
|
14
|
+
insertPragma: false,
|
|
15
|
+
htmlWhitespaceSensitivity: 'strict',
|
|
16
|
+
endOfLine: 'lf',
|
|
17
|
+
embeddedLanguageFormatting: 'auto',
|
|
18
|
+
}
|
package/bin/cli
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@raisenow/tamaro-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "RaiseNow",
|
|
6
|
+
"email": "development@raisenow.com"
|
|
7
|
+
},
|
|
8
|
+
"main": "bin/cli",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prepare": "npm run build",
|
|
11
|
+
"start": "npm run dev",
|
|
12
|
+
"dev": "npm run build -- --watch",
|
|
13
|
+
"build": "tsup src/cli.ts src/webpack.config.ts --format cjs",
|
|
14
|
+
"lint": "eslint .",
|
|
15
|
+
"lint:fix": "eslint . --fix"
|
|
16
|
+
},
|
|
17
|
+
"bin": "bin/cli",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=14"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@babel/cli": "^7.15.7",
|
|
23
|
+
"@babel/core": "^7.15.8",
|
|
24
|
+
"@babel/plugin-proposal-decorators": "^7.15.8",
|
|
25
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
26
|
+
"@babel/plugin-transform-runtime": "^7.15.8",
|
|
27
|
+
"@babel/preset-env": "^7.15.8",
|
|
28
|
+
"@babel/preset-react": "^7.14.5",
|
|
29
|
+
"@babel/preset-typescript": "^7.15.0",
|
|
30
|
+
"@babel/runtime": "^7.15.4",
|
|
31
|
+
"@babel/runtime-corejs3": "^7.15.4",
|
|
32
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
|
|
33
|
+
"@svgr/webpack": "^5.5.0",
|
|
34
|
+
"@types/columnify": "^1.5.1",
|
|
35
|
+
"@types/css-minimizer-webpack-plugin": "^3.0.2",
|
|
36
|
+
"@types/lodash": "^4.14.175",
|
|
37
|
+
"@types/mini-css-extract-plugin": "^2.3.0",
|
|
38
|
+
"@types/node": "^16.11.0",
|
|
39
|
+
"@types/node-notifier": "^8.0.1",
|
|
40
|
+
"@types/webpack-config-utils": "^2.3.1",
|
|
41
|
+
"@types/webpack-dev-server": "^4.3.1",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
43
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
44
|
+
"autoprefixer": "^10.3.7",
|
|
45
|
+
"babel-loader": "^8.2.2",
|
|
46
|
+
"babel-plugin-lodash": "^3.3.4",
|
|
47
|
+
"boxen": "^5.1.2",
|
|
48
|
+
"chalk": "^4.1.2",
|
|
49
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
50
|
+
"columnify": "^1.5.4",
|
|
51
|
+
"commander": "^8.2.0",
|
|
52
|
+
"core-js": "^3.18.3",
|
|
53
|
+
"css-loader": "^6.4.0",
|
|
54
|
+
"css-minimizer-webpack-plugin": "^3.1.1",
|
|
55
|
+
"current-script-polyfill": "^1.0.0",
|
|
56
|
+
"dotenv": "^10.0.0",
|
|
57
|
+
"dotenv-expand": "^5.1.0",
|
|
58
|
+
"element-closest": "^3.0.2",
|
|
59
|
+
"escape-string-regexp": "^4.0.0",
|
|
60
|
+
"eslint": "^8.0.1",
|
|
61
|
+
"eslint-config-prettier": "^8.3.0",
|
|
62
|
+
"eslint-plugin-node": "^11.1.0",
|
|
63
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
64
|
+
"eslint-plugin-promise": "^5.1.0",
|
|
65
|
+
"eslint-webpack-plugin": "^3.0.1",
|
|
66
|
+
"execa": "^5.1.1",
|
|
67
|
+
"file-loader": "^6.2.0",
|
|
68
|
+
"fork-ts-checker-webpack-plugin": "^6.3.4",
|
|
69
|
+
"glob": "^7.2.0",
|
|
70
|
+
"html-loader": "^2.1.2",
|
|
71
|
+
"html-webpack-plugin": "^5.4.0",
|
|
72
|
+
"json-loader": "^0.5.7",
|
|
73
|
+
"lodash": "^4.17.21",
|
|
74
|
+
"mini-css-extract-plugin": "^2.4.2",
|
|
75
|
+
"node-notifier": "^10.0.0",
|
|
76
|
+
"postcss": "^8.3.9",
|
|
77
|
+
"postcss-custom-properties": "^12.0.0",
|
|
78
|
+
"postcss-loader": "^6.2.0",
|
|
79
|
+
"prettier": "^2.4.1",
|
|
80
|
+
"react-refresh": "^0.10.0",
|
|
81
|
+
"regenerator-runtime": "^0.13.9",
|
|
82
|
+
"resolve-url-loader": "^4.0.0",
|
|
83
|
+
"sass": "^1.43.2",
|
|
84
|
+
"sass-loader": "^12.2.0",
|
|
85
|
+
"source-map-loader": "^3.0.0",
|
|
86
|
+
"strip-indent": "^3.0.0",
|
|
87
|
+
"style-loader": "^3.3.0",
|
|
88
|
+
"tailwindcss": "^0.7.4",
|
|
89
|
+
"ts-node": "^10.3.0",
|
|
90
|
+
"tsconfig-paths-webpack-plugin": "^3.5.1",
|
|
91
|
+
"tsup": "^5.4.0",
|
|
92
|
+
"typescript": "^4.4.4",
|
|
93
|
+
"unfetch": "^4.2.0",
|
|
94
|
+
"url-loader": "^4.1.1",
|
|
95
|
+
"webpack": "^5.58.2",
|
|
96
|
+
"webpack-cli": "^4.9.0",
|
|
97
|
+
"webpack-config-utils": "^2.3.1",
|
|
98
|
+
"webpack-dev-server": "^4.3.1",
|
|
99
|
+
"yaml-loader": "^0.6.0"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
2
|
+
import {Compiler} from 'webpack'
|
|
3
|
+
import escapeStringRegexp from 'escape-string-regexp'
|
|
4
|
+
|
|
5
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
type Replacements = {[key: string]: any}
|
|
8
|
+
|
|
9
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
10
|
+
|
|
11
|
+
class InterpolateHtmlPlugin {
|
|
12
|
+
replacements: Replacements
|
|
13
|
+
|
|
14
|
+
constructor(replacements: Replacements) {
|
|
15
|
+
this.replacements = {...replacements}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply(compiler: Compiler): void {
|
|
19
|
+
compiler.hooks.compilation.tap('InterpolateHtmlPlugin', (compilation) => {
|
|
20
|
+
const hooks = HtmlWebpackPlugin.getHooks(compilation)
|
|
21
|
+
|
|
22
|
+
hooks.alterAssetTagGroups.tap('InterpolateHtmlPlugin', (assets) => {
|
|
23
|
+
this.replacements['ENTRY'] = assets.headTags[0].attributes['src']
|
|
24
|
+
|
|
25
|
+
return assets
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
hooks.afterTemplateExecution.tap('InterpolateHtmlPlugin', (data) => {
|
|
29
|
+
// Run HTML through a series of user-specified string replacements.
|
|
30
|
+
Object.entries(this.replacements).forEach(([key, value]) => {
|
|
31
|
+
data.html = data.html.replace(
|
|
32
|
+
new RegExp(`%${escapeStringRegexp(key)}%`, 'g'),
|
|
33
|
+
value,
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return data
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default InterpolateHtmlPlugin
|
|
Binary file
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {createCommand} from 'commander'
|
|
2
|
+
import pkg from '../package.json'
|
|
3
|
+
import {dev} from 'commands/dev'
|
|
4
|
+
import {build} from 'commands/build'
|
|
5
|
+
|
|
6
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
7
|
+
|
|
8
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
9
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
|
10
|
+
// terminate the Node.js process with a non-zero exit code.
|
|
11
|
+
process.on('unhandledRejection', (error) => {
|
|
12
|
+
throw error
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Exit on ctrl+c
|
|
16
|
+
process.on('SIGINT', () => {
|
|
17
|
+
process.exit(0)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
21
|
+
|
|
22
|
+
const cli = createCommand().name(pkg.name).version(pkg.version, '-v, --version')
|
|
23
|
+
|
|
24
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
25
|
+
|
|
26
|
+
cli
|
|
27
|
+
.command('dev')
|
|
28
|
+
.description('Run dev server for Tamaro core or customer configuration')
|
|
29
|
+
.action(async () => {
|
|
30
|
+
await dev()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
cli
|
|
34
|
+
.command('build')
|
|
35
|
+
.description('Build Tamaro core or customer configuration for production')
|
|
36
|
+
.action(async () => {
|
|
37
|
+
await build()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
41
|
+
|
|
42
|
+
// cli
|
|
43
|
+
// .command('build')
|
|
44
|
+
// .description('Build customer config')
|
|
45
|
+
// .option('--deploy', 'Deploy to AWS')
|
|
46
|
+
// .option('--deploy-later', 'Build widget for deployment, but do not actually deploy it')
|
|
47
|
+
// .option('--latest', 'Deploy with tag "latest"')
|
|
48
|
+
// .option('--ns <ns>', 'Deploy widget to a specific namespace')
|
|
49
|
+
// .option('--tag <tag>', 'Deploy widget with a specific tag')
|
|
50
|
+
// .action(async (options: BuildOptions) => {
|
|
51
|
+
// await build(options)
|
|
52
|
+
// })
|
|
53
|
+
|
|
54
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
55
|
+
;(async () => {
|
|
56
|
+
await cli.parseAsync(process.argv)
|
|
57
|
+
})()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {commandSync} from 'execa'
|
|
2
|
+
import {
|
|
3
|
+
logCommand,
|
|
4
|
+
notify,
|
|
5
|
+
resolveWebpackBin,
|
|
6
|
+
resolveWebpackConfig,
|
|
7
|
+
} from 'lib/helpers'
|
|
8
|
+
|
|
9
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
10
|
+
|
|
11
|
+
export const build = async (): Promise<void> => {
|
|
12
|
+
const cmd = `${resolveWebpackBin()} --config ${resolveWebpackConfig()} --env min`
|
|
13
|
+
logCommand(cmd)
|
|
14
|
+
commandSync(cmd, {stdio: 'inherit'})
|
|
15
|
+
|
|
16
|
+
process.on('exit', () => {
|
|
17
|
+
notify({
|
|
18
|
+
title: '"build" command',
|
|
19
|
+
message: 'Process is done',
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {commandSync} from 'execa'
|
|
2
|
+
import {logCommand, resolveWebpackBin, resolveWebpackConfig} from 'lib/helpers'
|
|
3
|
+
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
|
|
6
|
+
export const dev = async (): Promise<void> => {
|
|
7
|
+
const cmd = `${resolveWebpackBin()} serve --config ${resolveWebpackConfig()}`
|
|
8
|
+
logCommand(cmd)
|
|
9
|
+
commandSync(cmd, {stdio: 'inherit'})
|
|
10
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import {resolve} from 'path'
|
|
3
|
+
import {notify as nodeNotify} from 'node-notifier'
|
|
4
|
+
|
|
5
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
export const logCommand = (...args: any[]): void => {
|
|
8
|
+
console.log(chalk.dim(...args))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
export const resolveWebpackBin = (): string => {
|
|
14
|
+
// __dirname is "dist" in runtime
|
|
15
|
+
return resolve(__dirname, '../node_modules/.bin/webpack')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
19
|
+
|
|
20
|
+
export const resolveWebpackConfig = (): string => {
|
|
21
|
+
// __dirname is "dist" in runtime
|
|
22
|
+
return resolve(__dirname, './webpack.config.js')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
26
|
+
|
|
27
|
+
export type NotifyArgs = {
|
|
28
|
+
title: string
|
|
29
|
+
message: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const notify = (args: NotifyArgs): void => {
|
|
33
|
+
const {title, message} = args
|
|
34
|
+
|
|
35
|
+
nodeNotify({
|
|
36
|
+
title,
|
|
37
|
+
message,
|
|
38
|
+
// __dirname is "dist" in runtime
|
|
39
|
+
contentImage: resolve(__dirname, '../src/assets/rnw-logo.jpg'),
|
|
40
|
+
sound: 'Funk',
|
|
41
|
+
})
|
|
42
|
+
}
|
package/src/polyfills.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import 'core-js/stable'
|
|
2
|
+
// import 'core-js/features/promise'
|
|
3
|
+
// import 'core-js/features/symbol'
|
|
4
|
+
// import 'core-js/features/object/assign'
|
|
5
|
+
// import 'core-js/features/string/match-all'
|
|
6
|
+
import 'element-closest/browser.js'
|
|
7
|
+
import 'unfetch/polyfill'
|
|
8
|
+
import 'current-script-polyfill'
|
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import {basename, dirname, resolve} from 'path'
|
|
2
|
+
import {existsSync, realpathSync} from 'fs'
|
|
3
|
+
import glob from 'glob'
|
|
4
|
+
import dotenv from 'dotenv'
|
|
5
|
+
import dotenvExpand from 'dotenv-expand'
|
|
6
|
+
import chalk from 'chalk'
|
|
7
|
+
import boxen from 'boxen'
|
|
8
|
+
import columnify from 'columnify'
|
|
9
|
+
import webpack, {
|
|
10
|
+
Configuration,
|
|
11
|
+
DefinePlugin,
|
|
12
|
+
IgnorePlugin,
|
|
13
|
+
ProgressPlugin,
|
|
14
|
+
RuleSetUseItem,
|
|
15
|
+
} from 'webpack'
|
|
16
|
+
import {getIfUtils, IfUtils, IfUtilsFn, removeEmpty} from 'webpack-config-utils'
|
|
17
|
+
import {TsconfigPathsPlugin} from 'tsconfig-paths-webpack-plugin'
|
|
18
|
+
import {CleanWebpackPlugin} from 'clean-webpack-plugin'
|
|
19
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
20
|
+
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
|
|
21
|
+
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
|
|
22
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
|
23
|
+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
|
|
24
|
+
// Needed for webpack-dev-server types to be picked up correctly
|
|
25
|
+
import {} from 'webpack-dev-server'
|
|
26
|
+
import InterpolateHtmlPlugin from './InterpolateHtmlPlugin'
|
|
27
|
+
import ESLintPlugin from 'eslint-webpack-plugin'
|
|
28
|
+
import stripIndent from 'strip-indent'
|
|
29
|
+
|
|
30
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
31
|
+
|
|
32
|
+
export type ResolveFn = (relativePath: string) => string
|
|
33
|
+
|
|
34
|
+
export type EnvVars = {
|
|
35
|
+
[key: string]: string | undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
39
|
+
// Supported packages
|
|
40
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
41
|
+
|
|
42
|
+
const TAMARO_CORE_PACKAGE_NAMES = ['@raisenow/tamaro-core', 'demo-tamaro-core']
|
|
43
|
+
const TAMARO_CONFIGURATIONS_PACKAGE_NAMES = [
|
|
44
|
+
'widget-tamaro-customer-configurations',
|
|
45
|
+
'demo-tamaro-customer-configurations',
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
49
|
+
|
|
50
|
+
const getIfCoreFns = (): IfUtils => {
|
|
51
|
+
const corePkgPath = resolve(realpathSync(process.cwd()), 'package.json')
|
|
52
|
+
const configsPkgPath = resolve(
|
|
53
|
+
realpathSync(process.cwd()),
|
|
54
|
+
'../../package.json',
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
if (existsSync(corePkgPath)) {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
59
|
+
const pkg = require(corePkgPath)
|
|
60
|
+
const name = pkg.name
|
|
61
|
+
|
|
62
|
+
if (TAMARO_CORE_PACKAGE_NAMES.includes(name)) {
|
|
63
|
+
return getIfUtils({core: true}, ['core'])
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (existsSync(configsPkgPath)) {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
69
|
+
const pkg = require(configsPkgPath)
|
|
70
|
+
const name = pkg.name
|
|
71
|
+
|
|
72
|
+
if (TAMARO_CONFIGURATIONS_PACKAGE_NAMES.includes(name)) {
|
|
73
|
+
return getIfUtils({core: false}, ['core'])
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.error(
|
|
78
|
+
chalk.red(
|
|
79
|
+
stripIndent(`\
|
|
80
|
+
You must run "dev" and "build" commands from:
|
|
81
|
+
1. Root of "${chalk.bold(TAMARO_CORE_PACKAGE_NAMES[0])}" package folder.
|
|
82
|
+
2. Root of particular customer configuration folder of "${chalk.bold(
|
|
83
|
+
TAMARO_CONFIGURATIONS_PACKAGE_NAMES[0],
|
|
84
|
+
)}" package.
|
|
85
|
+
You are currently in "${chalk.bold(realpathSync(process.cwd()))}".
|
|
86
|
+
`),
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
process.exit(0)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
93
|
+
// Paths
|
|
94
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
95
|
+
|
|
96
|
+
const moduleFileExtensions = ['ts', 'tsx', 'js', 'jsx']
|
|
97
|
+
const extensions = moduleFileExtensions.map((v) => `.${v}`)
|
|
98
|
+
|
|
99
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
100
|
+
|
|
101
|
+
const resolveModule = (resolveFn: ResolveFn, filePath: string) => {
|
|
102
|
+
const extension = moduleFileExtensions.find((extension) =>
|
|
103
|
+
existsSync(resolveFn(`${filePath}.${extension}`)),
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
if (extension) {
|
|
107
|
+
return resolveFn(`${filePath}.${extension}`)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return resolveFn(`${filePath}.js`)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
114
|
+
|
|
115
|
+
const resolveApp: ResolveFn = (relativePath) =>
|
|
116
|
+
resolve(realpathSync(process.cwd()), relativePath)
|
|
117
|
+
|
|
118
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
119
|
+
|
|
120
|
+
// __dirname is "dist" in runtime
|
|
121
|
+
const resolveOwn: ResolveFn = (relativePath) =>
|
|
122
|
+
resolve(__dirname, '..', relativePath)
|
|
123
|
+
|
|
124
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
125
|
+
|
|
126
|
+
const getPaths = (ifCore: IfUtilsFn) => {
|
|
127
|
+
return ifCore(
|
|
128
|
+
{
|
|
129
|
+
app: resolveApp('.'),
|
|
130
|
+
appEntry: resolveModule(resolveApp, 'src/index'),
|
|
131
|
+
appDist: resolveApp('dist'),
|
|
132
|
+
appNodeModules: resolveApp('node_modules'),
|
|
133
|
+
appTsConfig: resolveApp('tsconfig.json'),
|
|
134
|
+
appHtml: resolveApp('src/*.html'),
|
|
135
|
+
appEnv: resolveApp('.env'),
|
|
136
|
+
appTailwindConfig: resolveApp('tailwind.config.js'),
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
app: resolveApp('.'),
|
|
140
|
+
appEntry: resolveModule(resolveApp, 'widget'),
|
|
141
|
+
appDist: resolveApp(`../../dist/${process.env.WIDGET_UUID}`),
|
|
142
|
+
appNodeModules: resolveApp('../../node_modules'),
|
|
143
|
+
appTsConfig: resolveApp('../../tsconfig.json'),
|
|
144
|
+
appHtml: resolveApp('*.html'),
|
|
145
|
+
appEnv: resolveApp('.env'),
|
|
146
|
+
appTailwindConfig: undefined,
|
|
147
|
+
},
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
152
|
+
// Env
|
|
153
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
154
|
+
|
|
155
|
+
const getEnvVars = (filePath: string, ifMin: IfUtilsFn, ifCore: IfUtilsFn) => {
|
|
156
|
+
dotenvExpand(dotenv.config({path: filePath}))
|
|
157
|
+
|
|
158
|
+
process.env.NODE_ENV ??= ifMin('production', 'development')
|
|
159
|
+
process.env.BABEL_ENV ??= ifMin('production', 'development')
|
|
160
|
+
process.env.EXPOSE_VAR ??= ifCore('rnw.tamaroCore', 'rnw.tamaro')
|
|
161
|
+
process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET ??= ifCore(
|
|
162
|
+
'rnw-tamaro-core',
|
|
163
|
+
'rnw-tamaro',
|
|
164
|
+
)
|
|
165
|
+
process.env.WEBPACK_UNIQUE_NAME ??= ifCore('RnwTamaroCore', 'RnwTamaro')
|
|
166
|
+
|
|
167
|
+
// HMR doesn't work in ie11, it breaks everything.
|
|
168
|
+
// If you want to run dev-server and test in ie11, set HMR_ENABLED to 'false'
|
|
169
|
+
process.env.HMR_ENABLED ??= ifMin('false', 'true')
|
|
170
|
+
|
|
171
|
+
if (ifCore()) {
|
|
172
|
+
process.env.PRODUCT_NAME = 'tamaro'
|
|
173
|
+
|
|
174
|
+
const corePkgPath = resolve(realpathSync(process.cwd()), 'package.json')
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
176
|
+
const pkg = require(corePkgPath)
|
|
177
|
+
|
|
178
|
+
process.env.PRODUCT_VERSION = pkg.version
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (!ifCore()) {
|
|
182
|
+
process.env.WIDGET_UUID = basename(resolveApp('.'))
|
|
183
|
+
|
|
184
|
+
const version = process.env.CORE_VERSION
|
|
185
|
+
? `@${process.env.CORE_VERSION}`
|
|
186
|
+
: ''
|
|
187
|
+
|
|
188
|
+
process.env.CORE_URL ??= `https://cdn.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// var names which will be exposed along with "PUBLIC_*" var names
|
|
192
|
+
const varNames = [
|
|
193
|
+
// common
|
|
194
|
+
'NODE_ENV',
|
|
195
|
+
'BABEL_ENV',
|
|
196
|
+
'EXPOSE_VAR',
|
|
197
|
+
'ELEMENT_ATTRIBUTE_DATA_WIDGET',
|
|
198
|
+
'WEBPACK_UNIQUE_NAME',
|
|
199
|
+
|
|
200
|
+
// core
|
|
201
|
+
'PRODUCT_NAME',
|
|
202
|
+
'PRODUCT_VERSION',
|
|
203
|
+
|
|
204
|
+
// config
|
|
205
|
+
'WIDGET_UUID',
|
|
206
|
+
'CORE_URL',
|
|
207
|
+
'CORE_VERSION', // must be explicitly specified in each config
|
|
208
|
+
'IS_CREDIT_CARD_IFRAME',
|
|
209
|
+
|
|
210
|
+
// // todo: Environment variables for twint-qr-base
|
|
211
|
+
// 'EPMS_ENV',
|
|
212
|
+
// 'SOLUTION_CONFIG_BASE_URL',
|
|
213
|
+
// 'SHORT_ID_RESOLUTION_URL',
|
|
214
|
+
// 'HANDSHAKE_RESOLUTION_URL',
|
|
215
|
+
// 'TWINT_CHECKOUT_PAGE',
|
|
216
|
+
]
|
|
217
|
+
|
|
218
|
+
// Collect all vars which names start from "PUBLIC_" or present in "varNames" array
|
|
219
|
+
const raw = Object.keys(process.env)
|
|
220
|
+
.filter((key) => /^PUBLIC_/.test(key) || varNames.includes(key))
|
|
221
|
+
.reduce<EnvVars>((env, key) => {
|
|
222
|
+
env[key] = process.env[key]
|
|
223
|
+
|
|
224
|
+
return env
|
|
225
|
+
}, {})
|
|
226
|
+
|
|
227
|
+
// Stringify all values so we can feed into webpack DefinePlugin
|
|
228
|
+
const stringified = {
|
|
229
|
+
'process.env': Object.keys(raw).reduce<EnvVars>((env, key) => {
|
|
230
|
+
env[key] = JSON.stringify(raw[key])
|
|
231
|
+
|
|
232
|
+
return env
|
|
233
|
+
}, {}),
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return {raw, stringified}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
240
|
+
// Stats
|
|
241
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
242
|
+
|
|
243
|
+
// Reduce stats output verbosity
|
|
244
|
+
const stats: Configuration['stats'] = {
|
|
245
|
+
modules: false,
|
|
246
|
+
children: false,
|
|
247
|
+
chunks: false,
|
|
248
|
+
env: true,
|
|
249
|
+
entrypoints: true,
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
253
|
+
// Other
|
|
254
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
255
|
+
|
|
256
|
+
const imageInlineSizeLimit = 0
|
|
257
|
+
// const imageInlineSizeLimit = 8 * 1024 // 8kb
|
|
258
|
+
|
|
259
|
+
// Log data into console as a table
|
|
260
|
+
const logDataTable = (
|
|
261
|
+
vars: {[key: string]: string | undefined},
|
|
262
|
+
title: string,
|
|
263
|
+
): void => {
|
|
264
|
+
const boxTitle = chalk.bold(`${title}:\n`)
|
|
265
|
+
const boxTable = columnify(vars, {showHeaders: false})
|
|
266
|
+
|
|
267
|
+
// eslint-disable-next-line no-console
|
|
268
|
+
console.log(
|
|
269
|
+
boxen(`${boxTitle}\n${boxTable}`, {
|
|
270
|
+
margin: 0,
|
|
271
|
+
padding: {
|
|
272
|
+
top: 0,
|
|
273
|
+
right: 1,
|
|
274
|
+
bottom: 0,
|
|
275
|
+
left: 1,
|
|
276
|
+
},
|
|
277
|
+
borderColor: 'green',
|
|
278
|
+
}),
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
283
|
+
// Webpack config
|
|
284
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
285
|
+
|
|
286
|
+
const getWebpackConfig = async (env: any): Promise<Configuration> => {
|
|
287
|
+
const {ifMin, ifNotMin} = getIfUtils(env, ['min'])
|
|
288
|
+
const {ifCore} = getIfCoreFns()
|
|
289
|
+
const paths = getPaths(ifCore)
|
|
290
|
+
const appHtmlFiles = glob.sync(paths.appHtml)
|
|
291
|
+
const envVars = getEnvVars(paths.appEnv, ifMin, ifCore)
|
|
292
|
+
const {ifHmr} = getIfUtils({hmr: process.env.HMR_ENABLED === 'true'}, ['hmr'])
|
|
293
|
+
|
|
294
|
+
logDataTable(paths, 'Paths')
|
|
295
|
+
logDataTable(envVars.raw, 'Environment variables')
|
|
296
|
+
|
|
297
|
+
const getCssLoaders = (cssOptions: any = {}): RuleSetUseItem[] => {
|
|
298
|
+
return removeEmpty([
|
|
299
|
+
ifMin({loader: MiniCssExtractPlugin.loader}),
|
|
300
|
+
ifNotMin({
|
|
301
|
+
loader: require.resolve('style-loader'),
|
|
302
|
+
options: {
|
|
303
|
+
attributes: {
|
|
304
|
+
'data-widget': process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET,
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
}),
|
|
308
|
+
{
|
|
309
|
+
loader: require.resolve('css-loader'),
|
|
310
|
+
options: {
|
|
311
|
+
sourceMap: ifNotMin(),
|
|
312
|
+
importLoaders: 3,
|
|
313
|
+
esModule: false,
|
|
314
|
+
...cssOptions,
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
loader: require.resolve('postcss-loader'),
|
|
319
|
+
options: {
|
|
320
|
+
postcssOptions: {
|
|
321
|
+
plugins: removeEmpty([
|
|
322
|
+
ifCore([require.resolve('tailwindcss'), paths.appTailwindConfig]),
|
|
323
|
+
require.resolve('postcss-custom-properties'),
|
|
324
|
+
require.resolve('autoprefixer'),
|
|
325
|
+
]),
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
loader: require.resolve('resolve-url-loader'),
|
|
331
|
+
options: {sourceMap: ifNotMin()},
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
loader: require.resolve('sass-loader'),
|
|
335
|
+
options: {sourceMap: ifNotMin()},
|
|
336
|
+
},
|
|
337
|
+
])
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const config: Configuration = {
|
|
341
|
+
mode: ifMin('production', 'development'),
|
|
342
|
+
resolve: {
|
|
343
|
+
symlinks: false,
|
|
344
|
+
extensions: [...extensions, '...'],
|
|
345
|
+
modules: ['node_modules', paths.appNodeModules],
|
|
346
|
+
plugins: [
|
|
347
|
+
new TsconfigPathsPlugin({
|
|
348
|
+
configFile: paths.appTsConfig,
|
|
349
|
+
extensions,
|
|
350
|
+
}),
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
entry: [resolveOwn('src/polyfills.js'), paths.appEntry],
|
|
354
|
+
output: {
|
|
355
|
+
publicPath: 'auto',
|
|
356
|
+
path: ifMin(paths.appDist, undefined),
|
|
357
|
+
pathinfo: false,
|
|
358
|
+
filename: ifCore('index.js', 'widget.js'),
|
|
359
|
+
chunkFilename: ifMin('[name]-[contenthash:16].js', '[name].js'),
|
|
360
|
+
// assetModuleFilename: ifMin('assets/[name]-[contenthash:16][ext]', 'assets/[name][ext]'),
|
|
361
|
+
assetModuleFilename: 'assets/[name]-[contenthash:16][ext]',
|
|
362
|
+
crossOriginLoading: 'anonymous',
|
|
363
|
+
uniqueName: process.env.WEBPACK_UNIQUE_NAME,
|
|
364
|
+
},
|
|
365
|
+
stats,
|
|
366
|
+
module: {
|
|
367
|
+
rules: removeEmpty([
|
|
368
|
+
// Source maps
|
|
369
|
+
ifNotMin({
|
|
370
|
+
enforce: 'pre',
|
|
371
|
+
exclude: /@babel\/runtime/,
|
|
372
|
+
test: /\.(js|jsx|ts|tsx|css|scss)$/,
|
|
373
|
+
use: require.resolve('source-map-loader'),
|
|
374
|
+
}),
|
|
375
|
+
|
|
376
|
+
// Javascript and Typescript (Babel)
|
|
377
|
+
{
|
|
378
|
+
test: /\.(js|ts)x?$/,
|
|
379
|
+
exclude: /node_modules/,
|
|
380
|
+
loader: require.resolve('babel-loader'),
|
|
381
|
+
options: {
|
|
382
|
+
babelrc: false,
|
|
383
|
+
configFile: false,
|
|
384
|
+
sourceMaps: ifNotMin(),
|
|
385
|
+
inputSourceMap: ifNotMin(),
|
|
386
|
+
presets: removeEmpty([
|
|
387
|
+
require.resolve('@babel/preset-env'),
|
|
388
|
+
[
|
|
389
|
+
require.resolve('@babel/preset-typescript'),
|
|
390
|
+
{
|
|
391
|
+
allowDeclareFields: true,
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
require.resolve('@babel/preset-react'),
|
|
395
|
+
]),
|
|
396
|
+
plugins: removeEmpty([
|
|
397
|
+
[
|
|
398
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
399
|
+
{
|
|
400
|
+
corejs: {
|
|
401
|
+
version: 3,
|
|
402
|
+
proposals: true,
|
|
403
|
+
},
|
|
404
|
+
absoluteRuntime: dirname(
|
|
405
|
+
require.resolve('@babel/runtime/package.json'),
|
|
406
|
+
),
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
[
|
|
410
|
+
require.resolve('@babel/plugin-proposal-decorators'),
|
|
411
|
+
{
|
|
412
|
+
legacy: true,
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
require.resolve('@babel/plugin-syntax-dynamic-import'),
|
|
416
|
+
require.resolve('babel-plugin-lodash'),
|
|
417
|
+
ifHmr(require.resolve('react-refresh/babel')),
|
|
418
|
+
]),
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
|
|
422
|
+
// Styles (not modules)
|
|
423
|
+
{
|
|
424
|
+
test: /\.s?css$/,
|
|
425
|
+
exclude: /\.module\.s?css$/,
|
|
426
|
+
use: getCssLoaders({
|
|
427
|
+
modules: false,
|
|
428
|
+
}),
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
// Styles (modules)
|
|
432
|
+
{
|
|
433
|
+
test: /\.module\.s?css$/,
|
|
434
|
+
use: getCssLoaders({
|
|
435
|
+
modules: {localIdentName: '[local]__[hash:base64]'},
|
|
436
|
+
}),
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
// SVG (in HTML)
|
|
440
|
+
{
|
|
441
|
+
test: /\.svg$/,
|
|
442
|
+
issuer: /\.html$/,
|
|
443
|
+
type: 'asset',
|
|
444
|
+
parser: {
|
|
445
|
+
dataUrlCondition: {
|
|
446
|
+
maxSize: imageInlineSizeLimit,
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
|
|
451
|
+
// SVG (in components)
|
|
452
|
+
{
|
|
453
|
+
test: /\.svg$/,
|
|
454
|
+
issuer: {
|
|
455
|
+
not: [/\.html$/],
|
|
456
|
+
},
|
|
457
|
+
use: [
|
|
458
|
+
{
|
|
459
|
+
loader: require.resolve('@svgr/webpack'),
|
|
460
|
+
options: {
|
|
461
|
+
svgoConfig: {
|
|
462
|
+
plugins: [
|
|
463
|
+
{
|
|
464
|
+
removeHiddenElems: false,
|
|
465
|
+
moveGroupAttrsToElems: false,
|
|
466
|
+
collapseGroups: false,
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
loader: require.resolve('url-loader'),
|
|
474
|
+
options: {
|
|
475
|
+
// name: ifMin(
|
|
476
|
+
// 'assets/[name]-[contenthash:16].[ext]',
|
|
477
|
+
// 'assets/[name].[ext]'
|
|
478
|
+
// ),
|
|
479
|
+
name: 'assets/[name]-[contenthash:16].[ext]',
|
|
480
|
+
limit: imageInlineSizeLimit,
|
|
481
|
+
},
|
|
482
|
+
},
|
|
483
|
+
],
|
|
484
|
+
},
|
|
485
|
+
|
|
486
|
+
// Images and fonts
|
|
487
|
+
{
|
|
488
|
+
test: /\.(png|jpe?g|webp|gif|ico|ttf|eot|woff2?)$/,
|
|
489
|
+
type: 'asset',
|
|
490
|
+
parser: {
|
|
491
|
+
dataUrlCondition: {
|
|
492
|
+
maxSize: imageInlineSizeLimit,
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
|
|
497
|
+
// YML
|
|
498
|
+
{
|
|
499
|
+
test: /\.ya?ml$/,
|
|
500
|
+
use: [
|
|
501
|
+
{loader: require.resolve('json-loader')},
|
|
502
|
+
{loader: require.resolve('yaml-loader')},
|
|
503
|
+
],
|
|
504
|
+
},
|
|
505
|
+
|
|
506
|
+
// HTML
|
|
507
|
+
{
|
|
508
|
+
test: /\.html$/,
|
|
509
|
+
loader: require.resolve('html-loader'),
|
|
510
|
+
options: {
|
|
511
|
+
esModule: false,
|
|
512
|
+
minimize: false,
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
]),
|
|
516
|
+
},
|
|
517
|
+
|
|
518
|
+
devtool: ifMin(false, 'cheap-module-source-map'),
|
|
519
|
+
|
|
520
|
+
devServer: {
|
|
521
|
+
static: false,
|
|
522
|
+
historyApiFallback: {
|
|
523
|
+
disableDotRule: true,
|
|
524
|
+
},
|
|
525
|
+
hot: ifHmr(),
|
|
526
|
+
headers: {
|
|
527
|
+
'Access-Control-Allow-Origin': '*',
|
|
528
|
+
},
|
|
529
|
+
client: {
|
|
530
|
+
overlay: {
|
|
531
|
+
warnings: false,
|
|
532
|
+
errors: true,
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
|
|
537
|
+
optimization: {
|
|
538
|
+
// minimize: false,
|
|
539
|
+
removeEmptyChunks: true,
|
|
540
|
+
// moduleIds: 'deterministic', // todo: use instead of HashedModuleIdsPlugin
|
|
541
|
+
// chunkIds: 'named',
|
|
542
|
+
minimizer: ['...', new CssMinimizerPlugin()], // sourceMaps: true?
|
|
543
|
+
},
|
|
544
|
+
|
|
545
|
+
plugins: removeEmpty([
|
|
546
|
+
new ProgressPlugin(),
|
|
547
|
+
new ESLintPlugin({
|
|
548
|
+
extensions: ['js', 'jsx', 'ts', 'tsx'],
|
|
549
|
+
eslintPath: require.resolve('eslint'),
|
|
550
|
+
cwd: paths.app,
|
|
551
|
+
resolvePluginsRelativeTo: paths.app,
|
|
552
|
+
}),
|
|
553
|
+
ifMin(
|
|
554
|
+
new CleanWebpackPlugin({
|
|
555
|
+
// verbose: true,
|
|
556
|
+
}),
|
|
557
|
+
),
|
|
558
|
+
|
|
559
|
+
...appHtmlFiles.map(
|
|
560
|
+
(file) =>
|
|
561
|
+
new HtmlWebpackPlugin({
|
|
562
|
+
template: file,
|
|
563
|
+
filename: basename(file),
|
|
564
|
+
inject: false,
|
|
565
|
+
minify: false,
|
|
566
|
+
// ...ifMin({
|
|
567
|
+
// minify: {
|
|
568
|
+
// collapseWhitespace: true,
|
|
569
|
+
// removeComments: true,
|
|
570
|
+
// removeRedundantAttributes: true,
|
|
571
|
+
// removeScriptTypeAttributes: true,
|
|
572
|
+
// removeStyleLinkTypeAttributes: true,
|
|
573
|
+
// useShortDoctype: true,
|
|
574
|
+
// quoteCharacter: '"',
|
|
575
|
+
// minifyJS: true,
|
|
576
|
+
// minifyCSS: true,
|
|
577
|
+
// },
|
|
578
|
+
// }),
|
|
579
|
+
}),
|
|
580
|
+
),
|
|
581
|
+
|
|
582
|
+
new InterpolateHtmlPlugin(envVars.raw),
|
|
583
|
+
new DefinePlugin(envVars.stringified),
|
|
584
|
+
|
|
585
|
+
new ForkTsCheckerWebpackPlugin({
|
|
586
|
+
typescript: {
|
|
587
|
+
typescriptPath: require.resolve('typescript', {
|
|
588
|
+
paths: [paths.appNodeModules],
|
|
589
|
+
}),
|
|
590
|
+
configFile: paths.appTsConfig,
|
|
591
|
+
mode: 'write-references',
|
|
592
|
+
diagnosticOptions: {
|
|
593
|
+
syntactic: true,
|
|
594
|
+
semantic: true,
|
|
595
|
+
declaration: false,
|
|
596
|
+
global: false,
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
}),
|
|
600
|
+
|
|
601
|
+
ifHmr(new ReactRefreshWebpackPlugin()),
|
|
602
|
+
|
|
603
|
+
ifMin(
|
|
604
|
+
new MiniCssExtractPlugin({
|
|
605
|
+
filename: '[name]-[contenthash:16].css',
|
|
606
|
+
chunkFilename: '[name]-[contenthash:16].css',
|
|
607
|
+
ignoreOrder: true,
|
|
608
|
+
attributes: {
|
|
609
|
+
'data-widget': `${process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET}`,
|
|
610
|
+
},
|
|
611
|
+
}),
|
|
612
|
+
),
|
|
613
|
+
|
|
614
|
+
new IgnorePlugin({
|
|
615
|
+
resourceRegExp: /^\.\/locale$/,
|
|
616
|
+
contextRegExp: /moment$/,
|
|
617
|
+
}),
|
|
618
|
+
|
|
619
|
+
ifMin(new webpack.ids.HashedModuleIdsPlugin()), // todo: remove?
|
|
620
|
+
|
|
621
|
+
// ifMin(
|
|
622
|
+
// new CopyPlugin({
|
|
623
|
+
// patterns: [
|
|
624
|
+
// {
|
|
625
|
+
// from: 'docs',
|
|
626
|
+
// to: 'docs',
|
|
627
|
+
// },
|
|
628
|
+
// ],
|
|
629
|
+
// }),
|
|
630
|
+
// ),
|
|
631
|
+
|
|
632
|
+
// ifMin(new BundleAnalyzerPlugin()),
|
|
633
|
+
]),
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// console.log(util.inspect(config, {showHidden: false, depth: null}))
|
|
637
|
+
|
|
638
|
+
return removeEmpty(config)
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export default getWebpackConfig
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Basic Options */
|
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
+
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
|
8
|
+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
|
9
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
|
+
"allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
+
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
13
|
+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
+
// "outDir": "./", /* Redirect output structure to the directory. */
|
|
18
|
+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
|
+
// "composite": true, /* Enable project compilation */
|
|
20
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
+
"noEmit": true, /* Do not emit outputs. */
|
|
23
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
+
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
26
|
+
|
|
27
|
+
/* Strict Type-Checking Options */
|
|
28
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
+
|
|
37
|
+
/* Additional Checks */
|
|
38
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
+
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
43
|
+
|
|
44
|
+
/* Module Resolution Options */
|
|
45
|
+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
46
|
+
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */
|
|
47
|
+
"paths": { /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
48
|
+
"commands/*": ["src/commands/*"],
|
|
49
|
+
"lib/*": ["src/lib/*"]
|
|
50
|
+
},
|
|
51
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
52
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
53
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
54
|
+
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
55
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
56
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
57
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
58
|
+
|
|
59
|
+
/* Source Map Options */
|
|
60
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
61
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
62
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
63
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
64
|
+
|
|
65
|
+
/* Experimental Options */
|
|
66
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
67
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
68
|
+
|
|
69
|
+
/* Advanced Options */
|
|
70
|
+
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
71
|
+
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
|
72
|
+
|
|
73
|
+
/* Allow imports from json files */
|
|
74
|
+
"resolveJsonModule": true,
|
|
75
|
+
},
|
|
76
|
+
}
|