-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
94 lines (89 loc) · 2.21 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
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-env node */
const fs = require('fs');
const path = require('path');
const BannerPlugin = require('webpack').BannerPlugin;
const DefinePlugin = require('webpack').DefinePlugin;
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin;
const GitRevisionPlugin = require('git-revision-webpack-plugin');
function getVersionFromGit() {
const p = new GitRevisionPlugin({
versionCommand: '\
describe --tags --always --dirty --match=v* 2>/dev/null | sed \'s/^v//\' || \
cat ./.version 2> /dev/null || echo 0.0.0-unreleased'
});
return p.version();
}
const buildVersion = process.env.BUILD_VERSION || getVersionFromGit();
const buildDate = process.env.BUILD_DATE || new Date();
const target = process.env.TARGET || 'ES2015';
module.exports = {
resolve: {
extensions: ['.ts', '.js']
},
entry: [
__dirname + '/src/index.ts'
],
output: {
filename: 'glue.js',
path: path.resolve(__dirname, 'umd'),
publicPath: '/umd/',
library: 'Glue',
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'eslint-loader',
exclude: /node_modules/,
enforce: 'pre',
options: {
emitErrors: true,
failOnHint: false
}
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
compilerOptions: {
target: target,
declarationDir: 'umd/src'
}
}
}
]
},
devtool: 'source-map',
plugins: [
new UglifyJsPlugin({
sourceMap: true,
uglifyOptions: {
ecma: 8,
warnings: true,
output: {
comments: false
}
}
}),
new DefinePlugin({
__VERSION__: JSON.stringify(buildVersion)
}),
new LicenseWebpackPlugin({
pattern: /^(MIT|ISC|BSD.*)$/,
unacceptablePattern: /GPL/,
abortOnUnacceptableLicense: true,
perChunkOutput: false,
outputFilename: '../NOTICES.txt'
}),
new BannerPlugin(
fs.readFileSync(path.resolve(__dirname, 'LICENSE.txt')).toString()
+ '\n\n@version ' + buildVersion + ' (' + buildDate + ')' + ' ' + target
)
]
};