-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.ts
103 lines (99 loc) · 3.11 KB
/
webpack.common.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import CopyWebPackPlugin from "copy-webpack-plugin";
import HtmlWebPackPlugin from "html-webpack-plugin";
import FaviconsWebPackPlugin from "favicons-webpack-plugin";
import ExtractCssChunksWebPackPlugin from "extract-css-chunks-webpack-plugin";
import path from "path";
import webpack from "webpack";
export const SRC_DIR = path.resolve(__dirname, "src");
export const DIST_DIR = path.resolve(__dirname, "build");
const commonConfig: webpack.Configuration = {
entry: './src/index.tsx',
output: {
publicPath: "/",
path: DIST_DIR,
filename: 'static/js/app.bundle.[hash:5].js'
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".scss"],
alias: {
Components: `${SRC_DIR}/components`,
Constants: `${SRC_DIR}/constants`,
Apis: `${SRC_DIR}/apis`
}
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader"
}
],
},
{
test: /\.scss/,
exclude: /node_modules/,
use: [
{
loader: ExtractCssChunksWebPackPlugin.loader,
options: {
hmr: true
}
},
{
loader: "css-loader",
options: {
modules: {
mode: "local",
localIdentName: "[name]__[local]___[hash:base64:5]"
}
}
},
{ loader: "sass-loader" }
]
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
}),
new FaviconsWebPackPlugin({
logo: "./favicon.ico",
publicPath: '/static',
outputPath: '/static/assets'
}),
new CopyWebPackPlugin([
{
from: "./src/assets/robots/robots.prod.txt",
to: "robots.txt"
},
{
from: "./src/assets/google/google98b3d2999ea54121.html",
to: "google98b3d2999ea54121.html"
}
]),
new CleanWebpackPlugin(),
new ExtractCssChunksWebPackPlugin({
filename: 'static/css/[name].[hash].css',
chunkFilename: 'static/css/[id].[hash].css'
})
],
externals: {
"react": "React",
"react-dom": "ReactDOM"
}
};
export default commonConfig;