forked from icon-project/icon-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·84 lines (78 loc) · 1.99 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
/* global __dirname, require, module */
/* eslint-disable */
const webpack = require('webpack');
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const { CheckerPlugin } = require('awesome-typescript-loader');
const { env } = require('yargs').argv; // use --env with webpack 2
const LIBRARY_NAME = 'icon-sdk-js';
const MODE = {
PROD: 'production',
DEV: 'development'
};
const TARGET = {
WEB: 'web',
NODE: 'node'
};
const mode = env === 'build' ? MODE.PROD : MODE.DEV;
const setLibraryName = (libraryName, target, mode) =>
`${libraryName}.${target}.${mode === MODE.PROD ? 'min.js' : 'js'}`;
const setPlugin = target =>
target === 'web'
? [
new CheckerPlugin(),
new webpack.NormalModuleReplacementPlugin(
/(.*)\/module\/node$/,
function(resource) {
resource.request = resource.request.replace(/node/, `browser`);
}
)
]
: [new CheckerPlugin()];
const config = target => ({
mode,
entry: `${__dirname}/lib/index.ts`,
devtool: 'inline',
target,
output: {
path: `${__dirname}/build`,
filename: setLibraryName(LIBRARY_NAME, target, mode),
library: LIBRARY_NAME,
libraryTarget: 'umd',
umdNamedDefine: true,
/*
Resolve global, window no-def issue.
*/
globalObject: 'this'
},
module: {
rules: [
{
loader: 'awesome-typescript-loader',
test: /\.(t|j)s$/,
exclude: /(node_modules|bower_components|quickstart)/,
options: {
declaration: true
}
}
]
},
resolve: {
modules: [path.resolve('./node_modules')],
extensions: ['.json', '.js', '.ts']
},
// optimization: {
// minimizer: [
// new UglifyJsPlugin({
// cache: true,
// parallel: true,
// uglifyOptions: {
// mangle: true,
// compress: true
// }
// })
// ]
// },
plugins: setPlugin(target)
});
module.exports = [config(TARGET.WEB), config(TARGET.NODE)];