-
Notifications
You must be signed in to change notification settings - Fork 21
/
webpack.common.js
262 lines (261 loc) · 7.55 KB
/
webpack.common.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
const webpack = require('webpack')
const path = require('path')
const glob = require('glob')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
entry: {
adhocracy4: {
import: [ // array of entry points
'@fortawesome/fontawesome-free/scss/fontawesome.scss',
'@fortawesome/fontawesome-free/scss/brands.scss',
'@fortawesome/fontawesome-free/scss/regular.scss',
'@fortawesome/fontawesome-free/scss/solid.scss',
'select2/dist/css/select2.min.css',
'slick-carousel/slick/slick.css',
'./adhocracy-plus/assets/extra_css/_slick-theme.css',
'./adhocracy-plus/assets/scss/style.scss',
'./adhocracy-plus/assets/js/app.js'
],
// exposes a4 in this / window
library: {
name: '[name]',
type: 'this'
}
},
captcheck: {
import: [
'./apps/captcha/assets/captcheck.js'
],
// shares dependency so not loaded repeatedly
dependOn: 'adhocracy4'
},
datepicker: {
import: [
'./adhocracy-plus/assets/js/init-picker.js',
'./node_modules/flatpickr/dist/flatpickr.css'
],
dependOn: 'adhocracy4'
},
documents: {
import: [
'./apps/documents/assets/react_documents_init.jsx'
]
},
dsgvo_video_embed: {
import: [
'dsgvo-video-embed/dist/dsgvo-video-embed.min.css',
'dsgvo-video-embed/dist/dsgvo-video-embed.min.js'
],
dependOn: 'adhocracy4'
},
interactiveevents: {
import: [
'./apps/interactiveevents/assets/react_interactiveevents_init.jsx'
]
},
interactiveevents_presents: {
import: [
'./apps/interactiveevents/assets/react_interactiveevents_present_init.jsx'
]
},
init_dashboard_accordion: {
import: [
'./adhocracy-plus/assets/js/init_dashboard_accordion.js'
]
},
moderation_projects: {
import: [
'./apps/userdashboard/assets/js/a4_candy_userdashboard/react_moderation_projects.jsx'
]
},
moderation_notification_list: {
import: [
'./apps/userdashboard/assets/js/a4_candy_userdashboard/react_moderation_notification_list.jsx'
]
},
unload_warning: {
import: [
'./adhocracy-plus/assets/js/unload_warning.js'
],
dependOn: 'adhocracy4'
},
// A4 dependencies - we want all of them to go through webpack
a4maps_display_point: {
import: [
'leaflet/dist/leaflet.css',
'maplibre-gl/dist/maplibre-gl.css',
'adhocracy4/adhocracy4/maps/static/a4maps/a4maps_display_point.js'
],
dependOn: 'adhocracy4'
},
a4maps_display_points: {
import: [
'leaflet/dist/leaflet.css',
'maplibre-gl/dist/maplibre-gl.css',
'leaflet.markercluster/dist/MarkerCluster.css',
'adhocracy4/adhocracy4/maps/static/a4maps/a4maps_display_points.js'
],
dependOn: 'adhocracy4'
},
a4maps_choose_point: {
import: [
'leaflet/dist/leaflet.css',
'maplibre-gl/dist/maplibre-gl.css',
'adhocracy4/adhocracy4/maps/static/a4maps/a4maps_choose_point.js'
],
dependOn: 'adhocracy4'
},
a4maps_choose_polygon: {
import: [
'leaflet/dist/leaflet.css',
'maplibre-gl/dist/maplibre-gl.css',
'leaflet-draw/dist/leaflet.draw.css',
// overwrite the A4 version
'./apps/maps/assets/map_choose_polygon_with_preset.js'
],
dependOn: 'adhocracy4'
},
category_formset: {
import: [
'adhocracy4/adhocracy4/categories/assets/category_formset.js'
],
dependOn: 'adhocracy4'
},
image_uploader: {
import: [
'adhocracy4/adhocracy4/images/assets/image_uploader.js'
],
dependOn: 'adhocracy4'
},
poll_management: {
import: [
'adhocracy4/adhocracy4/polls/static/react_poll_management.jsx'
],
dependOn: 'adhocracy4'
},
polls: {
import: [
'adhocracy4/adhocracy4/polls/static/react_polls.jsx'
],
dependOn: 'adhocracy4'
},
select_dropdown_init: {
import: [
'adhocracy4/adhocracy4/categories/assets/select_dropdown_init.js'
],
dependOn: 'adhocracy4'
}
},
output: {
// creates a folder to store all assets
path: path.resolve('./adhocracy-plus/static/'),
// location they can be accessed, can also be a url
publicPath: '/static/'
},
externals: {
django: 'django'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules\/(?!(adhocracy4)\/).*/, // exclude all dependencies but adhocracy4
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'].map(require.resolve),
plugins: ['@babel/plugin-transform-runtime', '@babel/plugin-transform-modules-commonjs']
}
}
},
{
test: /\.s?css$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('autoprefixer')
]
}
}
},
{
loader: 'sass-loader'
}
]
},
{
test: /(fonts|files)\/.*\.(svg|woff2?|ttf|eot|otf)(\?.*)?$/,
// defines asset should always have seperate file
type: 'asset/resource',
generator: {
// defines custom location of those files
filename: 'fonts/[name][ext]'
}
},
{
test: /\.svg$|\.png$/,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext]'
}
}
]
},
resolve: {
// redirect module requests when normal resolving fails.
fallback: {
path: require.resolve('path-browserify')
},
// attempt to resolve these extensions in this order.
extensions: ['*', '.js', '.jsx', '.scss', '.css'],
// create aliases to import or require certain modules more easily, $ signifys exact match
alias: {
bootstrap$: 'bootstrap/dist/js/bootstrap.bundle.min.js',
'file-saver': 'file-saver/dist/FileSaver.min.js',
jquery$: 'jquery/dist/jquery.min.js',
shpjs$: 'shpjs/dist/shp.min.js',
'slick-carousel$': 'slick-carousel/slick/slick.min.js'
},
// when using `npm link` for a4 dev env, dependencies are resolved against the linked
// folder by default. This may result in dependencies being included twice.
// Resolving against node_modules will prevent this.
// concat merges node_modules and assets and syncs both to ensure no duplication.
modules: [
path.resolve('./node_modules')
].concat(
glob.sync('./apps/*/assets/js').map(e => { return path.resolve(e) })
)
},
plugins: [
// automatically load modules instead of import or require them everywhere.
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.$': 'jquery',
'window.jQuery': 'jquery',
timeago: 'timeago.js'
}),
// extracts CSS into separate files
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
// copies files or directories, to the build directory.
new CopyWebpackPlugin({
patterns: [{
from: './adhocracy-plus/assets/images/**/*',
to: 'images/[name][ext]'
}]
})
]
}