forked from ethanselzer/react-image-magnify
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
85 lines (83 loc) · 2.84 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
const path = require('path');
const ReactRefreshTypeScript = require('react-refresh-typescript');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const webpack = require('webpack');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const DIST = path.resolve('./dist');
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
module.exports = [{
devtool: 'source-map',
devServer: {
contentBase: DIST,
hot: true,
port: 3000,
historyApiFallback: true,
},
entry: ['./index.ts'],
externals: {
react: 'react',
'react-dom': 'reactDOM',
},
mode: IS_PRODUCTION ? 'production' : 'development',
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: [/node_modules/, /__tests__/, /__mocks__/, /stories/],
options: {
configFile: IS_PRODUCTION ? 'tsconfig.prod.json' : 'tsconfig.dev.json',
compilerOptions: {
module: 'commonjs',
target: 'es6',
},
getCustomTransformers: () => ({
before: [!IS_PRODUCTION && ReactRefreshTypeScript()].filter(Boolean),
}),
},
},
],
},
optimization: {
concatenateModules: true,
minimizer: [
new TerserJSPlugin({
parallel: 2,
}),
],
providedExports: true,
sideEffects: true,
usedExports: true,
},
output: {
path: DIST,
filename: 'index.js',
library: {
type: 'commonjs2',
},
},
plugins: [
new CleanWebpackPlugin(),
new BundleAnalyzerPlugin({
/**
* Can be `server`, `static` or `disabled`.
* In `server` mode analyzer will start HTTP server to show bundle report.
* In `static` mode single HTML file with bundle report will be generated.
* In `disabled` mode you can use this plugin to just generate Webpack Stats
* JSON file by setting `generateStatsFile` to true.
*/
analyzerMode: 'disabled',
}),
!IS_PRODUCTION ? new webpack.HotModuleReplacementPlugin() : null,
!IS_PRODUCTION ? new ReactRefreshWebpackPlugin() : null,
].filter(Boolean),
resolve: {
extensions: ['.tsx', '.ts', '.js'],
plugins: [new TsconfigPathsPlugin({
configFile: IS_PRODUCTION ? 'tsconfig.prod.json' : 'tsconfig.dev.json',
})],
},
}];