-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
98 lines (91 loc) · 2.58 KB
/
webpack.config.js
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
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')
const webpack = require('webpack')
const Dotenv = require('dotenv-webpack')
const { merge } = require('webpack-merge')
const { GitRevisionPlugin } = require('git-revision-webpack-plugin')
const gitRevisionPlugin = new GitRevisionPlugin()
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const libraryName = 'toky-sdk-alpha'
const modeConfig = (env) => require(`./build-utils/webpack.${env}`)()
const getEnvFile = function (key) {
const files = {
master: '.env.prod',
main: '.env.prod',
staging: '.env.staging',
dev: '.env.dev',
'dev-bundle': '.env.dev',
}
return files[key] || files.dev
}
module.exports = (env, argv) => {
const mode = argv.mode
const envFilePath = path.resolve(
__dirname,
getEnvFile(gitRevisionPlugin.branch())
)
const dotenv = new Dotenv({
path: envFilePath,
allowEmptyValues: true,
})
return merge(
{
target: 'web',
mode,
entry: __dirname + '/src/index.ts',
output: {
path: __dirname + '/dist',
filename: libraryName + '.js',
library: 'TokySDK',
libraryTarget: 'umd',
libraryExport: 'default',
globalObject: 'this',
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.m?js$/,
resolve: {
fullySpecified: false, // solve SIP.JS import problems
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', 'jsx'],
},
plugins: [
dotenv,
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(mode),
VERSION: JSON.stringify(gitRevisionPlugin.version()),
COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
LASTCOMMITDATETIME: JSON.stringify(
gitRevisionPlugin.lastcommitdatetime()
),
}),
new webpack.ProgressPlugin(),
new GitRevisionPlugin({
branch: true,
versionCommand: 'describe --always --tags',
}),
new CleanWebpackPlugin({
protectWebpackAssets: false,
cleanAfterEveryBuildPatterns: ['*.LICENSE.txt'],
}),
],
/**
* SIP.js would be treated as a peer dependency
* to reduce bundle size
*/
// externals: ['sip.js'],
},
modeConfig(mode)
)
}