/
webpack.config.js
101 lines (96 loc) · 2.2 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
let optimization = {
minimizer: [],
};
let outputFileName = 'main.js';
let mode = 'development';
if (process.env.NODE_ENV === 'production') {
optimization.minimizer.push(new UglifyJsPlugin());
outputFileName = 'main.min.js';
mode = 'production';
}
const config = {
entry: path.resolve(__dirname, 'src', 'app', 'js', 'main.ts'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: outputFileName,
libraryTarget: 'umd',
},
module: {
rules: [
{
test: /\.tsx?$/,
enforce: 'pre',
use: [
{
loader: 'tslint-loader',
options: {
"configFile": "tslint.json",
"tsConfigFile": "tsconfig.json",
"typeCheck": true
}
}
],
exclude: /(node_modules|bower_components)/,
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /(\.jsx|\.js)$/,
loader: 'babel-loader',
exclude: /(node_modules|bower_components)/,
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]?[hash]'
}
}
]
}
],
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ]
},
optimization,
mode,
devServer: {
contentBase: path.join(__dirname, 'src'),
compress: true,
port: 8100,
watchContentBase: true,
hot: true,
inline: true,
noInfo: true,
open: true,
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'index.html'),
hash: true,
inject: true,
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'src', 'app', 'static'),
to: 'assets/',
},
]),
],
};
module.exports = config;