-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
97 lines (92 loc) · 2.57 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
const path = require('path'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
MiniCssExtractPlugin = require("mini-css-extract-plugin"),
postcssPresetEnv = require('postcss-preset-env'),
FaviconsWebpackPlugin = require('favicons-webpack-plugin'),
PrettierPlugin = require("prettier-webpack-plugin"),
webpack = require("webpack"),
MinifyPlugin = require("babel-minify-webpack-plugin"),
{ CleanWebpackPlugin } = require('clean-webpack-plugin'),
CopyPlugin = require('copy-webpack-plugin');
require('dotenv').config();
const isDev = !process.env.ENV || process.env.ENV === "development",
plugins = [
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
GA_TRACKING_ID: JSON.stringify(process.env.GA_TRACKING_ID),
SITE_URL: JSON.stringify(process.env.SITE_URL)
}),
new PrettierPlugin(),
new HtmlWebpackPlugin({
template: './src/index.pug'
}),
new MiniCssExtractPlugin({
filename: '[hash].css'
}),
new FaviconsWebpackPlugin('./src/img/face.png'),
new CopyPlugin([{ from: 'src/public' }])
],
postCssLoaderPlugins = [postcssPresetEnv()];
if (!isDev) {
plugins.push(new MinifyPlugin());
postCssLoaderPlugins.push(require('cssnano')());
}
module.exports = {
entry: './src/js/index.js',
mode: process.env.ENV || "development",
devtool: isDev ? "source-map" : false,
output: {
filename: '[hash].js',
path: path.resolve(__dirname, 'dist')
},
devServer: {
contentBase: './dist',
},
module: {
rules: [
{
test: /\.pug$/,
use: ['pug-loader']
},
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
},
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.(s)?css$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: { sourceMap: isDev } },
{
loader: 'postcss-loader', options: {
sourceMap: isDev,
plugins: postCssLoaderPlugins
}
},
{ loader: "sass-loader", options: { sourceMap: isDev } },
]
},
{
test: /\.(mp3|woff(2)?|ttf|eot|svg|png|jp(e)?g)(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: "file-loader",
options: {
name: "[hash].[ext]",
}
}
}]
},
plugins
};