forked from dbis-uibk/relax
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
215 lines (200 loc) · 5.46 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*** Copyright 2016 Johannes Kessler 2016 Johannes Kessler
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin")
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = (env, options) => {
const mode = (
options
? options.mode
: env.mode
);
const isProduction = (mode !== 'development');
console.log(`build-mode: ${mode}`);
return {
mode: isProduction ? 'production' : 'development',
entry: {
'calc': [
'./src/calc2/calculator.entry.tsx',
],
'tests': [
'./src/db/tests/tests.entry.ts',
],
},
output: {
path: __dirname + "/dist/",
filename: isProduction ? "js/[name].[hash].bundle.js" : "js/[name].bundle.js",
publicPath: isProduction ? "/relax/" : "/",
},
devtool: isProduction ? '' : 'cheap-module-eval-source-map',
plugins: [
// https://github.com/johnagan/clean-webpack-plugin
new CleanWebpackPlugin({
dry: !isProduction,
verbose: false,
}),
// generate index.html
new HtmlWebpackPlugin({
title: 'relational algebra calculator',
template: 'src/calc2/index.ejs',
excludeAssets: [/test.*.(js|css)/],
}),
// generate test.html
new HtmlWebpackPlugin({
filename: 'test.html',
template: 'src/db/tests/test.ejs',
excludeAssets: [/calc.*.(js|css)/],
}),
new HtmlWebpackExcludeAssetsPlugin(),
new MiniCssExtractPlugin({
filename: !isProduction ? '[name].css' : '[name].[hash].css',
chunkFilename: !isProduction ? '[id].css' : '[id].[hash].css',
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"window.$": "jquery",
}),
// https://webpack.js.org/plugins/named-modules-plugin/
new webpack.NamedModulesPlugin(),
new webpack.EnvironmentPlugin({
'NODE_ENV': isProduction ? 'production' : 'development',
}),
// https://github.com/webpack-contrib/zopfli-webpack-plugin
(isProduction
? new CompressionPlugin({
test: /\.*/,
algorithm: 'gzip',
threshold: 0,
minRatio: 0.8,
cache: true,
deleteOriginalAssets: false,
})
: null
),
// https://github.com/kevlened/copy-webpack-plugin
new CopyWebpackPlugin([
{ from: 'src/calc2/manifest.json', to: './' },
{ from: 'resources/favicon/*', to: './assets/favicon/', flatten: true },
{ from: 'resources/logos/*', to: './assets/logos/', flatten: true },
]),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: '../reports/report.html',
defaultSizes: 'parsed',
openAnalyzer: false,
logLevel: 'info',
}),
].filter(e => !!e),
resolve: {
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.html'],
modules: [
path.join(__dirname, "src"),
'node_modules',
],
},
module: {
rules: [
{
test: /\.(htm|html)$/,
loader: 'file-loader',
options: {
'name': '[name].[ext]',
'outputPath': './',
},
},
{
test: /\.(eot|svg|ttf|woff|woff2|otf)$/,
loader: 'file-loader',
options: {
'name': isProduction ? '[name].[hash].[ext]' : '[name].[ext]',
'outputPath': './assets/',
},
},
{
test: /\.(txt)$/,
loader: 'raw-loader',
},
{
// https://github.com/eploko/pegjs-loader
test: /grammar_ra\.pegjs$/,
loader: 'pegjs-loader?cache=true&trace=false&allowedStartRules[]=start,allowedStartRules[]=groupStart',
},
{
// https://github.com/eploko/pegjs-loader
test: /grammar_bags\.pegjs$/,
loader: 'pegjs-loader?cache=true&trace=false&allowedStartRules[]=start,allowedStartRules[]=groupStart',
},
{
// https://github.com/eploko/pegjs-loader
test: /grammar_sql\.pegjs$/,
loader: 'pegjs-loader?cache=true&trace=false&allowedStartRules[]=start&allowedStartRules[]=dbDumpStart',
},
{
// normal js and ts code
test: /\.(ts|tsx|js|jsx)?$/,
exclude: /(node_modules|bower_components)/,
loader: [
{
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true,
}
},
],
},
{
test: /\.(css|scss)$/,
use: [
!isProduction ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
},
{
// use json5 loader to allow single and double line comments in json files
test: /\.(json5)?$/,
use: [
'json5-loader',
],
},
]
},
devServer: {
contentBase: path.join(__dirname, "dist"),
port: 8088,
clientLogLevel: 'info',
compress: true,
headers: {
//"X-Custom-Foo": "bar"
},
hotOnly: true,
/*proxy: {
"/relax": {
target: "http://localhost:8080",
pathRewrite: {"^/relax" : ""}
}
},*/
historyApiFallback: {
verbose: true,
//index: '404.html',
disableDotRule: true, // to get redirected from help.htm
},
//https: true,
}
}
};