This repository was archived by the owner on Jul 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
115 lines (112 loc) · 2.84 KB
/
webpack.config.js
File metadata and controls
115 lines (112 loc) · 2.84 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
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
require('dotenv').config();
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const isDevelopment = process.env.NODE_ENV === 'development';
const paths = {
dist: 'dist',
build: 'build',
};
/* -------------------------------------------------------------------------- */
module.exports = {
target: 'web',
mode: isDevelopment ? 'development' : 'production',
devtool: isDevelopment ? 'eval' : false,
devServer: {
contentBase: path.resolve(__dirname, paths.dist),
port: process.env.PORT,
writeToDisk: false,
compress: true,
overlay: true,
hot: true,
headers: {
'Cache-Control': 'max-age=31536000',
},
},
entry: {
main: './src/index.js',
survey: './src/survey.js',
},
output: {
publicPath: '/',
path: path.join(__dirname, isDevelopment ? paths.dist : paths.build),
filename: 'js/[name].bundle.js',
assetModuleFilename: 'images/[name][ext]',
},
module: {
rules: [
{
test: /\.s(a|c)ss$/i,
exclude: /node_modules/,
use: [
isDevelopment ? 'style-loader' : MiniCSSExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 2,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
postcssOptions: {
plugins: [
[
'postcss-preset-env',
{
stage: 3,
features: {
'nesting-rules': true,
},
autoprefixer: { grid: false },
},
],
],
},
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
{
test: /\.{png,jpe?g,gif,svg,webp,bmp}$/i,
exclude: /node_modules/,
type: 'asset',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, './src/index.html'),
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, './src/survey.html'),
filename: './survey.html',
chunks: ['survey'],
}),
new MiniCSSExtractPlugin({
linkType: false,
filename: 'css/style.css',
}),
new CopyPlugin({
patterns: [
{
from: path.join(__dirname, 'src/assets'),
to: path.join(
__dirname,
`${isDevelopment ? paths.dist : paths.build}/assets`,
),
},
],
}),
],
};