-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
79 lines (77 loc) · 2.03 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
const path = require('path');
const webpack = require('webpack');
const ESLintPlugin = require('eslint-webpack-plugin');
const pkg = require('./package.json');
const publicName = pkg.name; // package name
const banner = [
`${publicName} v${pkg.version}`,
`(c) 2021 Mark Lin.`,
pkg.license,
pkg.homepage,
].join(' | ');
module.exports = {
mode: 'production',
devtool: 'source-map',
entry: path.resolve(__dirname, 'src/index.ts'),
output: {
path: path.join(__dirname, 'lib'),
filename: 'index.js',
clean: true, // Clean the output directory before emit.
// Set mount to `this` for SSR https://webpack.js.org/configuration/output/#outputglobalobject
globalObject: 'this',
library: {
name: {
root: 'KeyDownKey',
commonjs: 'keydown-key',
amd: 'keydown-key',
},
/**
* Fix issue `Minified React error #321`
* An object with { root, amd, commonjs, ... } is only allowed for libraryTarget: 'umd'.
* It's not allowed for other library targets.
* https://webpack.js.org/configuration/externals/#object
*/
type: 'umd',
},
},
module: {
rules: [
// Process ts with Babel
{
test: /\.ts$/,
exclude: /(node_modules|coverage|lib)/,
use: {
loader: 'babel-loader',
},
},
{
// For our normal typescript
test: /\.ts$/,
exclude: /(node_modules|coverage|lib)/,
use: [
{
loader: 'ts-loader',
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
// This has effect on the react lib size
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new webpack.NoEmitOnErrorsPlugin(),
new ESLintPlugin({
eslintPath: require.resolve('eslint'),
exclude: ['node_modules', 'coverage', 'lib'],
emitWarning: true,
cache: false,
}),
new webpack.BannerPlugin(banner),
],
resolve: {
modules: ['src', 'node_modules'],
extensions: ['.js', '.ts'],
},
};