-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
163 lines (155 loc) · 4.81 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
/* !
* ddionrails - webpack configuration
* Copyright 2018-2019
* Licensed under AGPL (https://github.com/ddionrails/ddionrails/blob/master/LICENSE.md)
*/
"use strict";
const path = require("path");
const webpack = require("webpack");
const BundleTracker = require("webpack-bundle-tracker");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const config = {
context: __dirname,
entry: {
/* css and js libraries for ddionrails */
index: ["./assets/js/index.ts", "./assets/scss/index.scss"],
instrument_table: ["./assets/js/tables/instrument_table.ts"],
table_attachment: ["./assets/scss/table_attachment.scss"],
basket: "./assets/scss/basket.scss",
basket_button: "./assets/js/basket_button.ts",
basket_view_variable_buttons: "./assets/js/basket_view_variable_buttons.ts",
variable_view_basket_button: "./assets/js/variable_view_basket_button.ts",
variable_labels: "./assets/js/tables/variable_labels.ts",
dataset_table: "./assets/js/tables/dataset_table.ts",
variable_table: "./assets/js/tables/variable_table.ts",
question_table: "./assets/js/tables/question_table.ts",
search: ["./assets/js/search/main.js", "./assets/scss/search.scss"],
topics: ["./assets/js/topics.js", "./assets/scss/topics.scss"],
concept_table: [
"./assets/js/tables/concept_table.ts",
"./assets/scss/topics.scss",
],
feedback: ["./assets/js/feedback.ts"],
statistics: ["./assets/js/statistics.ts", "./assets/scss/statistics.scss"],
statistics_navigation: [
"./assets/js/statistics_navigation.ts",
"./assets/scss/statistics_navigation.scss",
],
focus_anchor: ["./assets/js/focus_anchor.ts"],
question_images: ["./assets/js/question_images.ts"],
questions: ["./assets/js/questions.ts", "./assets/scss/questions.scss"],
question_comparison: [
"./assets/js/question_comparison.ts",
"./assets/scss/question_comparison.scss",
],
description_modal: [
"./assets/js/description_modal.ts",
"./assets/scss/description_modal.scss",
],
variables: ["./assets/scss/variables.scss"],
visualization: [
"./assets/js/visualization.js",
"./assets/scss/visualization.scss",
],
},
output: {
path: path.resolve("./static/dist/"),
publicPath: "",
// filename is defined later; value depends on mode
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
}),
new BundleTracker({filename: "./webpack-stats.json"}),
new VueLoaderPlugin(),
new webpack.DefinePlugin({
"process.env.ELASTICSEARCH_DSL_INDEX_PREFIX": JSON.stringify(
process.env.ELASTICSEARCH_DSL_INDEX_PREFIX
),
"process.env.SHOW_STATISTICS": JSON.stringify(
process.env.SHOW_STATISTICS
),
}),
// reactivesearch-vue breaks without this.
// A false value breaks slider ui elements
new webpack.DefinePlugin({
"process.browser": true,
}),
],
module: {
rules: [
/* Typescript? */
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
/* Loads scss files, e.g. Bootstrap */
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
"css-loader",
"sass-loader",
],
},
/* Loads fonts, used for Bootstrap */
{
test: /\.(woff(2)?|ttf|eot|svg)$/,
type: "asset/resource",
generator: {
filename: "fonts/[name][ext]",
},
},
/* Loads static files, e.g. images */
{
test: /\.(png|jpg|gif|ico)$/,
type: "asset/resource",
generator: {
filename: "[name][ext]",
},
},
/* Loads vue single file components */
{
test: /\.vue$/,
use: "vue-loader",
},
/* Loads style block in vue single file components */
{
test: /\.css$/,
use: ["vue-style-loader", "css-loader", "sass-loader"],
},
],
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
modules: [path.resolve(__dirname, "node_modules")],
},
};
module.exports = (env, argv) => {
let cssFilename = "";
let chunkFilename = "";
const hashFormat = ".[contenthash]";
if (argv.mode === "development") {
config["output"]["filename"] = "[name].js";
cssFilename = "[name].css";
chunkFilename = "[id].css";
} else {
config["output"]["filename"] = `[name]${hashFormat}.js`;
cssFilename = `[name]${hashFormat}.css`;
chunkFilename = `[id]${hashFormat}.css`;
}
config["plugins"].push(
new MiniCssExtractPlugin({
filename: cssFilename,
chunkFilename,
ignoreOrder: false, // Enable to remove warnings about conflicting order
})
);
return config;
};