-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
125 lines (124 loc) · 3.01 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
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: {
digitalstrategie_berlin: [
'./digitalstrategie/assets/berlin_css/berlin_marketing.css',
],
digitalstrategie: [
'./digitalstrategie/assets/scss/style.scss'
],
newsletter: [
'./apps/home/assets/newsletter.js'
],
video: [
'./apps/home/assets/video.js'
],
captcheck: {
import: [
'./apps/captcha/assets/captcheck.js'
]
},
matomo: {
import: [
'./apps/contrib/assets/matomo.js'
]
},
wagtail: {
import: './apps/contrib/assets/wagtail.js'
}
},
output: {
libraryTarget: 'this',
library: '[name]',
// creates a folder to store all assets
path: path.resolve('./digitalstrategie/static/'),
// location they can be accessed, can also be a url
publicPath: '/static/'
},
externals: {
django: 'django'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules\/.*/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'].map(require.resolve)
}
}
},
{
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'],
modules: [
path.resolve('./node_modules')
].concat(
glob.sync('./apps/*/assets/js').map(e => { return path.resolve(e) })
)
},
plugins: [
// 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: './digitalstrategie/assets/images/**/*',
to: 'images/[name][ext]'
}]
})
]
}