This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.common.js
131 lines (128 loc) · 3.85 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
var MiniCssExtractPlugin = require('mini-css-extract-plugin')
var CopyWebpackPlugin = require('copy-webpack-plugin')
var path = require('path')
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
/** 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 `vendor.(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: [
'./advocate_europe/assets/scss/all.scss',
'./advocate_europe/assets/js/app.js'
],
vendor: [
'jquery',
'react',
'react-dom',
'react-addons-update',
'classnames',
'@fortawesome/fontawesome-free/scss/fontawesome.scss',
'@fortawesome/fontawesome-free/scss/brands.scss',
'@fortawesome/fontawesome-free/scss/regular.scss',
'@fortawesome/fontawesome-free/scss/solid.scss',
'./advocate_europe/assets/js/jquery-fix.js',
'bootstrap-sass',
'slick-carousel/slick/slick.min.js',
'slick-carousel/slick/slick.css'
]
},
output: {
libraryTarget: 'var',
library: '[name]',
path: path.resolve('./advocate_europe/static/'),
publicPath: '/static/',
filename: '[name].js'
},
externals: {
'django': 'django'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules\/(?!(adhocracy4|bootstrap)\/).*/, // exclude all dependencies but adhocracy4
loader: 'babel-loader',
query: {
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: {
ident: 'postcss',
plugins: [
require('autoprefixer')
]
}
},
{
loader: 'sass-loader',
options: {
includePaths: [
path.resolve('./node_modules/bootstrap-sass/assets/stylesheets')
]
}
}
]
},
{
test: /fonts\/.*\.(svg|woff2?|ttf|eot)(\?.*)?$/,
loader: 'file-loader?name=fonts/[name].[ext]'
},
{
test: /\.svg$|\.png$/,
loader: 'file-loader?name=images/[name].[ext]'
}
]
},
resolve: {
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')]
},
plugins: [
new webpack.optimize.SplitChunksPlugin({ name: 'vendor', filename: 'vendor.js'}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
new CopyWebpackPlugin([
{
from: './advocate_europe/assets/images/**/*',
to: 'images/',
flatten: true
},
{
from: './advocate_europe/assets/icons/**/*',
to: 'icons/',
flatten: true
}
])
]
}