|
1 | 1 | const path = require('path');
|
2 | 2 | const webpack = require('webpack');
|
3 |
| -const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); |
| 3 | +const TerserPlugin = require('terser-webpack-plugin'); |
| 4 | + |
| 5 | +const { |
| 6 | + name, |
| 7 | + version, |
| 8 | + repository, |
| 9 | + author, |
| 10 | + license |
| 11 | +} = require('./package.json'); |
4 | 12 |
|
5 | 13 | const isProduction = process.env.NODE_ENV === 'production';
|
6 |
| -const mode = isProduction ? 'production' : 'development'; |
7 | 14 |
|
8 | 15 | const libraryName = 'js-semaphore';
|
9 | 16 |
|
| 17 | +const banner = ` |
| 18 | + ${name} v${version} |
| 19 | + ${repository.url} |
| 20 | + Copyright (c) ${author.replace(/ *\<[^)]*\> */g, ' ')} |
| 21 | + This source code is licensed under the ${license} license found in the |
| 22 | + LICENSE file in the root directory of this source tree. |
| 23 | +`; |
| 24 | + |
10 | 25 | module.exports = {
|
11 |
| - mode, |
| 26 | + mode: isProduction ? 'production' : 'development', |
12 | 27 | entry: {
|
13 | 28 | [libraryName]: path.resolve(__dirname, 'src/index.js'),
|
14 | 29 | [`${libraryName}.min`]: path.resolve(__dirname, 'src/index.js')
|
15 | 30 | },
|
16 |
| - devtool: 'source-map', |
17 | 31 | output: {
|
18 |
| - path: path.resolve(__dirname, 'dist'), |
19 | 32 | filename: '[name].js',
|
| 33 | + path: path.resolve(__dirname, 'dist'), |
20 | 34 | library: libraryName,
|
21 | 35 | libraryTarget: 'umd',
|
22 |
| - umdNamedDefine: true, |
23 | 36 | globalObject: "typeof self !== 'undefined' ? self : this"
|
24 | 37 | },
|
25 | 38 | module: {
|
26 | 39 | rules: [
|
27 | 40 | {
|
28 | 41 | test: /\.js$/,
|
| 42 | + exclude: /node_modules/, |
29 | 43 | use: {
|
30 | 44 | loader: 'babel-loader',
|
31 | 45 | options: {
|
32 | 46 | presets: ['@babel/preset-env']
|
33 | 47 | }
|
34 |
| - }, |
35 |
| - exclude: /node_modules/ |
| 48 | + } |
36 | 49 | }
|
37 | 50 | ]
|
38 | 51 | },
|
39 | 52 | optimization: {
|
40 | 53 | minimize: true,
|
41 |
| - minimizer: [new UglifyJsPlugin({ include: /\.min\.js$/ })] |
| 54 | + minimizer: [new TerserPlugin()] |
42 | 55 | },
|
43 | 56 | plugins: [
|
44 | 57 | new webpack.DefinePlugin({
|
45 | 58 | 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
46 |
| - }) |
| 59 | + }), |
| 60 | + new webpack.BannerPlugin(banner) |
47 | 61 | ],
|
48 | 62 | resolve: {
|
49 | 63 | extensions: ['.json', '.js']
|
|
0 commit comments