This repository was archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
90 lines (88 loc) · 2.45 KB
/
webpack.config.js
File metadata and controls
90 lines (88 loc) · 2.45 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
78
79
80
81
82
83
84
85
86
87
88
89
90
/* eslint-disable no-console */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const chalk = require('chalk');
const semver = require('semver');
module.exports = (env, argv) => {
const dev = argv.mode === 'development';
if (!semver.satisfies(process.versions.node, '<=10.0.0')) {
console.error(`Incorrect Node version ${process.versions.node} detected, downgrade to a version lower than 10.x.x`);
process.exit();
}
return ({
entry: { main: './src/index.js' },
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js',
},
resolve: {
alias: {
handlebars: 'handlebars/dist/handlebars.min.js',
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.handlebars$/,
loader: 'text-loader',
},
{
test: /\.(sa|sc|c)ss$/,
use: [
dev ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
query: {
limit: 10000,
name: 'images/[name].[hash:7].[ext]',
},
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 1000,
name: 'fonts/[name].[hash:7].[ext]',
},
},
{
test: /\.(webm|mp4)$/,
loader: 'file-loader',
options: {
name: 'videos/[name].[hash:7].[ext]',
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
title: 'JS WEBPACK TUTORIAL',
template: path.resolve(__dirname, 'src/html/index.ejs'),
}),
new MiniCssExtractPlugin({
filename: dev ? '[name].css' : '[name].[hash].css',
chunkFilename: dev ? '[id].css' : '[id].[hash].css',
}),
new CleanWebpackPlugin(['dist'], {}),
new ProgressBarPlugin({
format: ` build [:bar] ${chalk.green.bold(':percent')} (:elapsed seconds)`,
clear: false,
}),
],
});
};