-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
77 lines (75 loc) · 2.68 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
/* eslint func-names: 0 */
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const Dotenv = require('dotenv-webpack');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const LodashWebpackPlugin = require('lodash-webpack-plugin');
module.exports = function(env, argv) {
const isProduction = argv.mode === 'production';
return {
entry: './index.tsx',
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
}),
new OptimizeCSSAssetsPlugin({}),
],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.ts(x)?$/,
include: [path.resolve(__dirname, 'index.tsx'), path.resolve(__dirname, 'src')],
loader: 'babel-loader',
},
{
test: /\.scss$/,
loaders: [
'style-loader',
{ loader: 'css-loader', options: { importLoaders: 1 } },
{ loader: 'postcss-loader', options: { options: {}, } },
'sass-loader',
],
}, {
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=100000',
include: [path.resolve(__dirname, 'src/resources/images')],
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: './index.html',
favicon: 'src/resources/favicon/favicon.ico',
}),
new MiniCssExtractPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new Dotenv(),
new LodashWebpackPlugin(),
new CopyPlugin([
{ from: 'src/resources/images/', to: 'images/' },
{ from: 'config.js', to: 'config.js' },
]),
],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
devServer: {
historyApiFallback: true,
},
};
};