-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.cjs
169 lines (152 loc) · 4.21 KB
/
webpack.config.cjs
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
var path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const {InjectManifest} = require('workbox-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin')
//const { v4: uuidv4 } = require('uuid');
const md5File = require('md5-file');
const Dotenv = require('dotenv-webpack');
//var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const fs = require('fs');
const packageJson = fs.readFileSync('./package.json');
const version = JSON.parse(packageJson).version || 0;
console.log("VERSION: "+version);
//const isDevelopment = process.env.NODE_ENV === 'development'
const isDevelopment = false;
module.exports = {
entry: {
'ergatas': './lib/index.js',
'ergatas.min': './lib/index.js',
},
mode: 'development',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
chunkFilename: '[name].js',
library: 'ergatas',
globalObject: 'this',
//libraryTarget: 'umd',
libraryTarget: 'var',
//publicPath: 'https://localhost:9000/',
publicPath: '/',
},
externals:{
jquery:"jQuery",
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
//["env",{modules:false}],
]
}
}
},
{
test:/\.css$/,
use: ['style-loader','css-loader'],
},
{
test:/\.(jpg)$/,
use: ['file-loader?name=[name].[ext]'],
},
{
test:/\.(ttf|otf|eot|svg|png)$/,
use: ['file-loader'],
},
{
test:/\.(woff|woff2)$/,
use: ['url-loader'],
},
{
test:/\.html$/,
use: ['html-loader'],
},
{
test: /\.module\.s(a|c)ss$/,
loader: [
isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
sourceMap: isDevelopment
}
},
{
loader: 'sass-loader',
options: {
sourceMap: isDevelopment
}
}
]
},
{
test: /\.s(a|c)ss$/,
exclude: /\.module.(s(a|c)ss)$/,
loader: [
isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'sass-loader',
options: {
sourceMap: isDevelopment
}
}
]
}
]
},
//watch:true,
watchOptions: {
ignored: [/node_modules/],
},
// optimization: {
// minimize: true,
// minimizer: [new UglifyJsPlugin({
// include: /\.min\.js$/
// })]
// },
plugins: [
new CleanWebpackPlugin(),
new Dotenv(),
new webpack.optimize.ModuleConcatenationPlugin(),
new MiniCssExtractPlugin(),
//new GenerateSW(),
new InjectManifest({
swSrc: path.resolve(__dirname, 'lib/client/service-worker.js'),
//by excluding these, the service worker won't change, which means the user
// won't be bothered to update it. js/html changes will be applied
// after 2 reloads.
//If this is not used (commented), then the service worker changes anytime
// the js/html/css changes and will prompt the user within an hour or so to reload
// the page to get the new changes. Seems better to do this for those using as an app.
//exclude: [/ergatas\.(js|min\.js|css|min\.css)/],
additionalManifestEntries:[
{
url:'index.html',
revision: md5File.sync(path.resolve(__dirname,"lib/page-templates/index.html"))
}],
}),
new webpack.DefinePlugin({
'process.env.PACKAGE_VERSION': '"' + version + '"'
}),
new CopyWebpackPlugin([ {
from: './node_modules/@fortawesome/fontawesome-free/webfonts',
to: './webfonts'
}]),
//new BundleAnalyzerPlugin(),
],
devServer: {
hot:false,
inline:false
}
};