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