-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
86 lines (81 loc) · 1.88 KB
/
webpack.config.ts
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
import path from 'path';
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
import TerserWebpackPlugin from 'terser-webpack-plugin';
import HTMLWebpackPlugin from 'html-webpack-plugin';
import DotenvCmd from 'dotenv-cmd-webpack';
import { Configuration } from 'webpack';
const isProd = process.env.NODE_ENV === 'production';
const entryPath = './src/index.tsx';
const prodOutput = path.resolve(__dirname, './dist');
export default {
mode: isProd ? 'production' : 'development',
entry: {
entryPath,
},
output: {
path: prodOutput,
filename: '[name].[hash].js',
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.s(a|c)ss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
},
{
test: /\.(ttf|woff|jpe?g|png|svg|gif)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
],
},
plugins: [
/*
* no need to specify env-cmd in dev mode in package.json
*/
DotenvCmd({
filePath: './.env-cmdrc.json',
env: isProd ? 'prod' : 'dev',
}),
new HTMLWebpackPlugin({
title: 'React with Webpack and Typescript Support Boilerplate',
template: './src/index.html',
favicon: 'assets/mocha_icon.png',
}),
new MonacoWebpackPlugin({
languages: ['typescript', 'javascript', 'cpp', 'python', 'json', 'ruby'],
}),
],
// only specified if environment is in production mode
optimization: isProd
? {
minimize: true,
minimizer: [new TerserWebpackPlugin()],
}
: {},
// only specified if the environment is in development mode
devServer: isProd
? {}
: {
port: 8080,
open: true,
hot: true,
compress: true,
stats: 'errors-only',
overlay: true,
},
} as Configuration;