-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwebpack.config.js
123 lines (120 loc) · 3.1 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const webpack = require("webpack");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const nodeEnv = process.env.NODE_ENV || "development";
const isProd = nodeEnv === "production";
const plugins = [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(nodeEnv)
}
}),
new HtmlWebpackPlugin({
title: "Typescript Fundamentals",
template: "!!ejs-loader!src/index.html",
chunks: ['app']
}),
new HtmlWebpackPlugin({
title: "Typescript Fundamentals",
template: "!!ejs-loader!src/fundamentals.html",
chunks: ["fundamentals"],
filename: "./fundamentals.html"
}),
new HtmlWebpackPlugin({
title: "Typescript Control Flow",
template: "!!ejs-loader!src/control-flow.html",
chunks: ["controlFlow"],
filename: "./control-flow.html"
}),
new HtmlWebpackPlugin({
title: "Typescript Array",
template: "!!ejs-loader!src/array.html",
chunks: ["array"],
filename: "./array.html"
}),
new HtmlWebpackPlugin({
title: "Typescript Function",
template: "!!ejs-loader!src/functions.html",
chunks: ["functions"],
filename: "./functions.html"
}),
new HtmlWebpackPlugin({
title: "Typescript Object",
template: "!!ejs-loader!src/object.html",
chunks: ["object"],
filename: "./object.html"
}),
new HtmlWebpackPlugin({
title: "Typescript Promise",
template: "!!ejs-loader!src/promise.html",
chunks: ["promise"],
filename: "./promise.html"
}),
new HtmlWebpackPlugin({
title: "Typescript Exercise",
template: "!!ejs-loader!src/exercise/index.html",
chunks: ["exercise"],
filename: "./exercise/index.html"
}),
new webpack.LoaderOptionsPlugin({
options: {
tslint: {
emitErrors: true,
failOnHint: true
}
}
}),
new MiniCssExtractPlugin({
filename: isProd ? "[name].[hash].css" : "[name].css",
chunkFilename: isProd ? "[id].[hash].css" : "[id].css"
})
];
const config = {
devtool: isProd ? false : "source-map",
context: path.resolve("./src"),
entry: {
app: "./index.ts",
fundamentals: "./fundamentals.ts",
controlFlow: "./control-flow.ts",
array: "./array.ts",
functions: "./functions.ts",
object: "./object.ts",
promise: "./promise.ts",
exercise: "./exercise/index.ts",
},
output: {
path: path.resolve("./dist"),
filename: "[name].bundle.js"
},
module: {
rules: [
{
test: /\.ts?$/,
exclude: /node_modules/,
use: ["awesome-typescript-loader", "source-map-loader"]
},
{ test: /\.html$/, loader: "html-loader" },
{
test: /\.(sa|sc|c)ss$/,
use: [
isProd ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
"sass-loader"
]
}
].filter(Boolean)
},
resolve: {
extensions: [".ts", ".js"]
},
plugins: plugins,
devServer: {
contentBase: path.join(__dirname, "src/"),
compress: true,
port: 3000,
hot: true,
watchContentBase: true
}
};
module.exports = config;