forked from stylescape/unit.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
182 lines (144 loc) · 5.84 KB
/
webpack.prod.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// webpack.prod.js
// ============================================================================
// Imports
// ============================================================================
import path from "path"
import { fileURLToPath } from "url";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
// import CopyWebpackPlugin from "copy-webpack-plugin";
import TerserPlugin from "terser-webpack-plugin";
// import { CleanWebpackPlugin } from "clean-webpack-plugin";
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
// ============================================================================
// Constants
// ============================================================================
// Resolve current directory
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Production Webpack Configuration
*
*/
export const configProduction = {
// Configuration | mode
// ========================================================================
// Set the mode to development or production
mode: "production",
// Configuration | Entry Points
// ========================================================================
// Entry points for the application
// Where webpack looks to start building the bundle
entry: "./src/scss/index.scss",
// Configuration | Output
// ========================================================================
// output: {
// library: "Stylescape",
// libraryTarget: "umd",
// libraryExport: "default",
// path: path.resolve(__dirname, "dist"),
// // path: path.resolve(__dirname, "dist"),
// filename: "js/stylescape.js",
// clean: true, // Clean the output directory before emit
// },
// Configuration | Module Rules
// ========================================================================
// Module rules for handling different file types.
// Determine how modules within the project are treated.
// module: {
// rules: [
// // CSS and SCSS Rules
// // ----------------------------------------------------------------
// // Handles importing CSS and SCSS files. Use MiniCssExtractPlugin
// // in production and style-loader in development
// {
// test: /\.(scss|css)$/,
// exclude: /node_modules/,
// use: [
// // Extract CSS into separate files
// MiniCssExtractPlugin.loader,
// ]
// },
// ],
// },
// Configuration | Plugins
// ========================================================================
plugins: [
// Clean the output directory before build.
// Removes/cleans build folders and unused assets when rebuilding
// new CleanWebpackPlugin(),
// Extracts CSS into separate files for production
new MiniCssExtractPlugin(
{
filename: "css/stylescape.css",
// filename: "[name].[contenthash].css"
}
),
// Copies files from target to destination folder
// new CopyWebpackPlugin(
// {
// patterns: [
// {
// from: "src/font",
// to: "font",
// globOptions: {
// ignore: ["*.DS_Store"],
// },
// noErrorOnMissing: true,
// }
// ]
// }
// ),
],
// Configuration | Optimization
// ========================================================================
optimization: {
minimizer: [
// Minify CSS
new CssMinimizerPlugin(),
// Minify JavaScript
new TerserPlugin(
{
terserOptions: {
format: {
// Remove comments in the minified output
comments: false,
},
},
extractComments: false,
},
),
],
},
// Configuration | Performance
// ========================================================================
// Performance settings to control webpack"s hints
// In production, performance is a key factor, and you want to ensure that
// your assets are optimized and not excessively large. You can enforce
// size limits and configure warnings or errors for assets that exceed
// these limits.
performance: {
// Maximum size (in bytes) for a single asset.
maxAssetSize: 5000000,
// Maximum size (in bytes) for the entry point"s assets.
maxEntrypointSize: 5000000,
// Show an error for assets or entry points exceeding limits.
// hints: "error",
// Warns when assets or entry points exceed the set limits.
hints: "warning",
},
// Configuration | Devtool
// ========================================================================
// Control how source maps are generated.
// In production, you may choose to disable source maps for performance
// and security reasons. However, if you need them for debugging, use a
// setting that minimizes the impact on performance:
// Turn off source maps in production for better performance
devtool: false,
// This option omits column mappings for smaller file sizes, but preserves
// line mappings for error reports.
// devtool: "source-map",
};
// ============================================================================
// Exports
// ============================================================================
export default configProduction