-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.js
151 lines (144 loc) · 3.51 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
const CopyWebpackPlugin = require("copy-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require("webpack");
require("dotenv").config();
const pack = require("./package.json");
function testJSON(text) {
if (typeof text !== "string") {
return false;
}
try {
JSON.parse(text);
return true;
} catch (error) {
return false;
}
}
module.exports = (env) => {
const production = !!(env && env.production === "true");
const babelSettings = {
extends: path.join(__dirname, "/.babelrc")
};
const serverList = testJSON(process.env.SERVER_LIST)
? JSON.parse(process.env.SERVER_LIST)
: null;
const singleServer = testJSON(process.env.SINGLE_SERVER)
? JSON.parse(process.env.SINGLE_SERVER)
: null;
const logoLabel = process.env.LOGO_LABEL;
const config = {
entry: "./sources/app.js",
output: {
path: path.join(__dirname, "codebase"),
publicPath: "",
filename: "app.js"
},
mode: "development",
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.js?$/,
exclude: {
and: [/node_modules/]
},
use: [
{
loader: "babel-loader",
options: {
...babelSettings
}
}
]
},
{
test: /\.(svg|png|jpg|gif)$/,
type: "asset/resource"
},
{
test: /\.(less|css)$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"]
},
{
test: /\.html$/,
exclude: /node_modules/,
use: {loader: "html-loader"}
},
{
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/inline"
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/inline"
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/inline"
}
]
},
resolve: {
extensions: [".js"],
modules: ["./sources", "node_modules"],
alias: {
"jet-views": path.resolve(__dirname, "sources/views"),
"jet-locales": path.resolve(__dirname, "sources/locales")
}
},
devServer: {
host: process.env.DEV_HOST || "0.0.0.0",
port: process.env.DEV_PORT || 5000,
// Path to all other files (e.g. index.html and webix):
static: [
{
directory: path.join(__dirname, "./codebase")
}
]
},
plugins: [
new webpack.DefinePlugin({
VERSION: `"${pack.version}"`,
APPNAME: `"${pack.name}"`,
PRODUCTION: production
}),
new CopyWebpackPlugin({
patterns: [
{from: path.resolve(__dirname, "sources/images/"), to: "sources/images"},
{from: path.resolve(__dirname, "node_modules/webix/"), to: "webix"},
{from: path.resolve(__dirname, "index.html")},
{from: path.resolve(__dirname, "node_modules/paper/"), to: "paper"},
{from: path.resolve(__dirname, "node_modules/openseadragon/"), to: "openseadragon"}
]
}),
new webpack.EnvironmentPlugin({
SERVER_LIST: serverList,
SINGLE_SERVER: singleServer,
// ENABLE/DISABLE MODULES (TABS)
TABSTATE: {
metadata: "enable",
applyFilter: "enable",
pathologyReport: "enable",
aperioAnnotations: "disable"
},
LOGO_LABEL: logoLabel,
}),
new Dotenv({
path: path.resolve(__dirname, ".env") // Path to .env file
}),
new MiniCssExtractPlugin()
]
};
if (production) {
config.plugins.push(
new TerserPlugin({
test: /\.js(\?.*)?$/i
})
);
}
return config;
};