-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
107 lines (100 loc) · 2.64 KB
/
webpack.config.ts
File metadata and controls
107 lines (100 loc) · 2.64 KB
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
100
101
102
103
104
105
106
107
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
import HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
import HtmlWebpackPlugin = require('html-webpack-plugin');
import MiniCssExtractPlugin = require('mini-css-extract-plugin');
import CopyWebpackPlugin = require('copy-webpack-plugin');
import * as path from 'path';
import * as webpack from 'webpack';
import merge = require('webpack-merge');
import * as dotenv from 'dotenv';
const env = dotenv.config().parsed;
// reduce it to a nice object, the same as before
const envKeys = Object.keys(env as any).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify((env as any)[next]);
return prev;
}, {});
const isDevelopment = process.env.NODE_ENV === 'development';
const commonConfig: webpack.Configuration = {
mode: 'production',
entry: {
app: [path.join(__dirname, 'src/app/index.tsx')],
vendor: ['react', 'react-dom', 'mobx', 'mobx-react'],
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].bundle.js',
pathinfo: false,
},
devtool: 'eval',
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: true,
},
},
},
{
test: /\.(sa|sc|c)ss$/,
use: [
isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
},
],
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src/app/index.html'),
}),
new webpack.DefinePlugin(envKeys),
new MiniCssExtractPlugin(),
],
};
const devConfig = merge(commonConfig, {
mode: 'development',
entry: {
app: ['react-hot-loader/patch', 'webpack-hot-middleware/client'],
},
output: {
pathinfo: false,
},
optimization: {
removeAvailableModules: false,
removeEmptyChunks: false,
splitChunks: false,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HardSourceWebpackPlugin(),
],
});
let config = commonConfig;
if (isDevelopment) {
config = devConfig;
}
export default config;