-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
webpack.config.js
168 lines (157 loc) · 4.35 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
var config = require("./config.js");
const path = require("path");
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
//const TARGET = process.env.npm_lifecycle_event;
const getSkinExample = (skin) => {
switch (skin) {
case "":
return ["/project_website/base.html"];
case "covis":
return ["/local_covis/"];
case "triple":
return ["/local_triple/map.html"];
case "viper":
return "/local_viper/";
default:
return false;
}
};
module.exports = (env) => {
const { publicPath, skin } = { ...config, ...env };
return {
devtool: "eval-source-map",
entry: "./vis/entrypoint.js",
output: {
path: path.resolve(__dirname, "dist"),
//dev: specify a full path including protocol, production: specify full path excluding protocol
publicPath: publicPath,
filename: "headstart.js",
libraryTarget: "var",
library: "headstart",
},
devServer: {
open: getSkinExample(skin),
static: {
directory: path.resolve(__dirname, "examples/"),
},
allowedHosts: "all",
devMiddleware: { publicPath: "/dist/" },
},
resolve: {
alias: {
//
hypher: "hypher/dist/jquery.hypher.js",
markjs: "mark.js/dist/jquery.mark.js",
// paths
templates: path.resolve(__dirname, "vis/templates"),
images: path.resolve(__dirname, "vis/images"),
lib: path.resolve(__dirname, "vis/lib"),
styles: path.resolve(__dirname, "vis/stylesheets"),
// modules
config: path.resolve(__dirname, "vis/js/default-config.js"),
headstart: path.resolve(__dirname, "vis/js/headstart.js"),
mediator: path.resolve(__dirname, "vis/js/mediator.js"),
io: path.resolve(__dirname, "vis/js/io.js"),
// building
process: "process/browser",
},
},
externals: {
chart: "Chart",
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// all options are optional
filename: "headstart.css",
chunkFilename: "[id].css",
ignoreOrder: false, // Enable to remove warnings about conflicting order
}),
// can be used for simulating env variables
new webpack.EnvironmentPlugin({}),
],
module: {
rules: [
{
test: require.resolve("hypher/dist/jquery.hypher.js"),
use: [
{
loader: "imports-loader",
options: {
imports: ["default jquery $", "default jquery jQuery"],
},
},
],
},
{
test: /lib\/*.js/,
use: [
{
loader: "imports-loader",
options: {
imports: ["default jquery $", "default jquery jQuery"],
},
},
],
},
{
test: /.jsx?$/,
resolve: { extensions: [".js", ".jsx"] },
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
},
},
],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/resource",
},
{
test: /\.png$/,
use: [
{
loader: "file-loader?name=img/[name].[ext]",
options: { exclude: /examples/ },
},
],
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: "style-loader",
},
{
loader: MiniCssExtractPlugin.loader,
options: { esModule: false },
},
{
loader: "css-loader",
},
{
loader: "sass-loader",
options: {
additionalData: `
$skin: "${skin}";
`,
sassOptions: {
includePaths: ["node_modules"],
},
},
},
],
},
{ test: /\.csl$/, type: "asset/source" },
],
},
};
};