Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
77 lines (69 loc) · 1.92 KB
/
Copy pathwebpack.config.js
File metadata and controls
77 lines (69 loc) · 1.92 KB
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
const webpack = require("webpack");
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const isProduction = process.env.NODE_ENV === "production";
const config = {
mode: isProduction ? "production" : "development",
devtool: isProduction ? "source-map" : "eval-cheap-module-source-map",
entry: {
app: path.join(__dirname, './src/index.ts'),
styles: path.join(__dirname, './src/assets/styles/index.css')
},
output: {
path: isProduction
? path.join(__dirname, "build")
: path.join(__dirname, "dist"),
filename: `[name].bundle.js`,
},
module: {
rules: [
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: {
loader: "file-loader",
options: {
name: "[path][name].[ext]",
},
},
},
{
test: /\.js$/i,
exclude: /node_modules/,
use: ['babel-loader', 'source-map-loader'],
},
{
test: /\.ts$/i,
exclude: /node_modules/,
use: ['babel-loader', 'ts-loader'],
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
],
},
plugins: [
// SET 'process.env.NODE_ENV' CONSTANT THROUGH ALL APP
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
}),
new CopyWebpackPlugin({
patterns: [{ from: "./src/assets", to: "assets" }],
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, "./src/index.html"),
}),
// CLEAN 'DIST' FOLDER IN DEVELOPMENT MODE
isProduction
? new CleanWebpackPlugin()
: new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [path.join(__dirname, "dist")],
}),
],
resolve: {
extensions: ['.ts', '.js'],
},
};
module.exports = config;