-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.common.js
165 lines (163 loc) · 4.71 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
const webpack = require('webpack')
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
/** How do we use webpack to handle static files?
*
* - dependencies (js, scss, and css) are installed via npm
* - dependencies (js, scss, and css ) are moved to `adhocracy.(js|css)`
* by specifing them in the vendor entry point
* - everything else (our js, scss) is compiled into app.(js|css)
* - our images, fonts, icons, js, css and scss is either in each apps
* static folder (/euth/<appname>/static) or in the projects asset folder
* (/euth_wagtail/assets)
* - after running webpack all static ressources will be in the
* project static folder (/euth_wagtail/static) and can then be served
* by django
* - webpack compiles jsx+es2015 to js and scss to css for us
*/
module.exports = {
entry: {
adhocracy4: [
'@fortawesome/fontawesome-free/scss/fontawesome.scss',
'@fortawesome/fontawesome-free/scss/brands.scss',
'@fortawesome/fontawesome-free/scss/regular.scss',
'@fortawesome/fontawesome-free/scss/solid.scss',
'slick-carousel/slick/slick.min.js',
'slick-carousel/slick/slick.css',
'./euth_wagtail/assets/js/modernizr-custom.js',
'./euth_wagtail/assets/scss/all.scss',
'./euth_wagtail/assets/js/app.js'
],
captcheck: {
import: [
'./euth/captcha/assets/captcheck.js'
],
dependOn: 'adhocracy4'
},
popover_init: {
import: [
'./euth_wagtail/assets/js/popover_init.js'
],
dependOn: 'adhocracy4'
}
},
// exposes exports of entry points
output: {
library: {
name: '[name]',
type: 'this' // return value of entry point will be assigned this.
},
path: path.resolve('./euth_wagtail/static'),
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',
options: {
url: {
filter: (url, resourcePath) => {
// only handle `/` urls, leave rest in code (pythong images to be left)
if (!url.startsWith('/')) {
return true
} else {
return false
}
}
}
}
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('autoprefixer')
]
}
}
},
{
loader: 'sass-loader'
}
]
},
{
test: /(fonts|files)\/.*\.(svg|woff2?|ttf|eot|otf)(\?.*)?$/,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext]'
}
},
{
test: /\.svg$|\.png$/,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext]'
}
}
]
},
resolve: {
fallback: {
path: require.resolve('path-browserify')
},
extensions: ['*', '.js', '.jsx', '.scss', '.css'],
// when using `npm link`, dependencies are resolved against the linked
// folder by default. This may result in dependencies being included twice.
// Setting `resolve.root` forces webpack to resolve all dependencies
// against the local directory.
modules: [path.resolve('./node_modules')],
alias: {
bootstrap$: 'bootstrap/dist/js/bootstrap.bundle.min.js',
jquery$: 'jquery/dist/jquery.min.js'
}
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.$': 'jquery',
'window.jQuery': 'jquery'
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
new CopyWebpackPlugin({
patterns: [{
from: './euth_wagtail/assets/images/*',
to: 'images/[name][ext]'
},
{
from: './euth_wagtail/assets/icons/*',
to: 'icons/[name][ext]'
},
{
from: './euth_wagtail/assets/category_icons/**/*',
to: 'category_icons/icons/[name][ext]'
}]
})
]
}