-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
104 lines (90 loc) · 3.26 KB
/
webpack.common.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
const paths = require('./paths')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
// configuring polyfill compatible with webpack5
// const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
module.exports = {
// target: "node" for in-nodejs environment
target: "web",
// Webpack will start looking in here
entry: [paths.src + '/index.js'],
// Webpack will put the bundle (compressed file) and resources (images) here
output: {
path: paths.build,
publicPath: '/',
filename: '[name].bundle.js',
},
// Customization of the webpack build process
plugins: [
// configuring polyfill compatible with webpack5
// new NodePolyfillPlugin(),
// cleans build folder and unused resources when re-building
new CleanWebpackPlugin(),
// copy resources from target to destination
new CopyWebpackPlugin(
{
patterns: [
{
from: paths.static,
to: 'assets',
toType: 'dir'
}
]
}
),
// generates an html file from the template
new HtmlWebpackPlugin({
template: paths.src + '/html/init_template.html', // input file
filename: 'index.html' // output file
}),
// IMPORTANT: add plugin for prodiving jquery
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
// IMPORTANT: add replacement for mqtt
new webpack.NormalModuleReplacementPlugin(/^mqtt$/, "mqtt/dist/mqtt.js")
],
// define how modules are treated for this project
module: {
rules: [
// use babel transcompiler for making javasctipt files compatible with old webbrowsers
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader']
},
// inject css into the head
{
test: /\.(scss|css)$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { sourceMap: true, importLoaders: 1 } },
{ loader: 'postcss-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: {sourceMap: true } }
]
},
// copy images into the build folder
{
test: /\.(?:ico|gif|png|jpg|jpeg|webp|svg)$/i,
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
context: 'src' // prevent display of src/ in filename
}
},
// inline font files
{
test: /\.(woff(2)?|eot|ttf|otf|)$/,
loader: 'url-loader',
options: {
limit: 8192,
name: '[path][name].[ext]',
context: 'src' // prevent display of src/ in filename
}
}
]
}
}