-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.config.js
99 lines (90 loc) · 2.27 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
99
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const ESLintPlugin = require('eslint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const pkJson = require('./package.json');
const license = fs.readFileSync('./LICENSE', 'utf-8');
const copyright = (licenseFile) => `
${pkJson.displayName} v${pkJson.version}
----------------------------------------
Copyright (c) ${new Date().getFullYear()} ${pkJson.author}.
Homepage: ${pkJson.homepage}
Released under the ${pkJson.license} License.
License information can be found in ${licenseFile}.
`;
const configs = {
entry: './src/main.ts',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'main.js',
library: {
name: pkJson.name,
type: 'umd',
umdNamedDefine: true,
},
globalObject: 'this',
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
{
test: /\.scss$/,
use: [
'css-loader',
'sass-loader',
],
},
],
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
'@': path.resolve(__dirname, './src'),
},
},
plugins: [
new webpack.BannerPlugin(license),
new ESLintPlugin({
cache: true,
eslintPath: require.resolve('eslint'),
resolvePluginsRelativeTo: __dirname,
ignore: true,
useEslintrc: true,
extensions: ['ts', 'js'],
}),
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [path.resolve(__dirname, './dist')],
}),
],
};
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
return {
...configs,
devtool: 'source-map',
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
terserOptions: {
sourceMap: true,
compress: isProduction,
},
extractComments: {
filename: 'LICENSE.txt',
banner: copyright,
},
}),
],
},
};
}