-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
100 lines (98 loc) · 2.84 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
const path = require("path");
const webpack = require("webpack");
const autoprefixer = require("autoprefixer");
const htmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = (env, argv) => {
const mode = process.env.NODE_ENV || "development";
const isProduction = mode === "production";
return {
mode: mode,
entry: {
main: [
path.resolve(__dirname, "src/index.tsx")
]
},
output: {
filename: isProduction ? "bundle.[chunkhash].js" : "[name].js",
path: path.resolve(__dirname, "dist")
},
devtool: isProduction ? false : "source-map",
resolve: {
extensions: [".ts", ".tsx", ".js", ".json", ".css", ".scss", ".jpg", ".jpeg", ".gif", ".png", ".bmp", ".tiff", "woff", "eot", "ttf", ".svg", ".ico"]
},
optimization: {
splitChunks: {
name: "vendor",
chunks: "initial",
}
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
importLoaders: 2,
modules: true,
localIdentName: "[name]-[local]-[hash:base64:5]",
sourceMap: !isProduction,
minimize: isProduction
}
},
{
loader: "typed-css-modules-loader",
options: {
camelCase: true,
searchDir: "./src",
outDir: "./typings"
}
},
{
loader: "postcss-loader",
options: {
sourceMap: !isProduction,
plugins: [
autoprefixer()
]
}
}, {
loader: "sass-loader"
}
]
})
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
}, {
test: /\.(png|jpe?g|gif|bmp|tiff|woff|eot|ttf|svg|ico)$/,
use: [{
loader: "url-loader",
options: {
limit: 8192,
name: isProduction ? "[name]-[hash].[ext]" : "[name].[ext]"
}
}]
}
]
},
plugins: [
new htmlWebpackPlugin({
template: path.resolve(__dirname, "src/index.html"),
}),
new ExtractTextPlugin({
filename: isProduction ? "bundle.[chunkhash].css" : "[name].css",
allChunks: true
}),
]
}
}