/
webpack.config.js
132 lines (128 loc) 路 2.91 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
124
125
126
127
128
129
130
131
132
/* === dont forget to import scss to main.js file === */
/* ===> import './main.scss'; <=== */
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = {
// if we need multiple entry points they are passed in via an array
entry: './src/js/index.js',
output: {
// uses nodejs path built in function to handle the absolute path to the root folder
path: path.resolve(__dirname, 'dist'),
// name of the final output file
filename: 'scripts/min.js'
},
optimization: {
minimizer: [
// minifyjs
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: false, // set to true if you want JS source maps
extractComments: true
}),
// minifycss
new OptimizeCssAssetsPlugin({})
],
// this is used to export the css from the js file import into a seperate css file
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true
}
}
},
},
devServer: {
contentBase: './src',
watchContentBase: true,
},
plugins: [
new MiniCssExtractPlugin({
filename: "scripts/min.css",
})
],
module: {
rules:[
{
test: /\.js$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
presets: [
["@babel/preset-env", {
useBuiltIns: 'usage',
corejs: "3.14.0"
}], // uses preset-env and calls on babel polyfils based on usage
],
babelrc: false
}
}]
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader, // extracts css from js and makes a sep cssfile
options: {
publicPath: '../',
}
},
{
loader: "css-loader", // translates CSS into CommonJS
},
{
loader: 'postcss-loader', // used to autoprefix
options: {plugins:[require('autoprefixer')()]}
},
{
loader: 'resolve-url-loader', // used to resolve image urls in css
},
{
loader: "sass-loader", // compiles Sass to CSS
options: {
// source maps must be on so that we can resolve the image urls in css
sourceMap: true,
sourceMapContents: false
}
}
],
},
{
test: /\.html$/,
use: [
{ loader: "file-loader",
options: {
name: "[name].[ext]"
}
},
{ loader: "extract-loader" },
{ loader: "html-loader",
options: {
attrs: ["img:src", "use:href"],
minimize: true,
}
}
]
},
{
test: /\.(jpe?g|png|gif|svg)$/,
use: [
{ loader: "file-loader",
options: {
name: "img/[name].[ext]"
}
}
]
},
]
},
}
// One big note:
// outputPath is place where your want to save files
// publicPath is what url you have in js, css and etc files.