-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
111 lines (110 loc) · 3.43 KB
/
webpack.common.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
102
103
104
105
106
107
108
109
110
111
const webpack = require('webpack');
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackRootPlugin = require('html-webpack-root-plugin');
const PrettierWebpackPlugin = require('prettier-webpack-plugin');
module.exports = {
entry: {
main: './src/index.tsx',
vendor: ['react', 'react-router', 'lodash', 'rxjs'],
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
title: 'react-webpack-starter',
inject: 'body',
}),
new HtmlWebpackRootPlugin('app'),
new webpack.NamedModulesPlugin(
chunk =>
chunk.name
? chunk.name
: chunk.modules.map(m => path.relative(m.context, m.request)).join('_'),
),
//new PrettierWebpackPlugin(require('./prettier.config')),
],
resolve: {
alias: {
src: path.resolve(__dirname, 'src'),
},
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
output: {
filename: '[name].[hash].bundle.js',
chunkFilename: '[chunkhash].chunk.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
optimization: {
splitChunks: {
chunks: 'async',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
minChunks: Infinity,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
runtimeChunk: {
name: entrypoint => `runtimechunk~${entrypoint.name}`,
},
},
module: {
rules: [
{
parser: {
requireEnsure: false,
},
},
{
test: /\.tsx?$/,
use: 'awesome-typescript-loader',
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ['file-loader'],
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[hash:base64:5]',
camelCase: true,
sourceMap: true,
importLoaders: 2,
},
},
{
loader: 'postcss-loader',
options: {
parser: 'postcss-scss', // sugarss
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
require('autoprefixer')({
flexbox: 'no-2009',
}),
],
},
},
'sass-loader',
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: ['file-loader'],
},
],
},
};