-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
210 lines (202 loc) · 6.78 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
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const Webpack = require('webpack');
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const { dependencies } = require('./package.json');
module.exports = {
target: 'web',
entry: {
index: path.resolve(__dirname, './src/index.jsx'),
olStyle: 'ol/ol.css',
olLayerSwitcherStyle: 'ol-layerswitcher/src/ol-layerswitcher.css',
mcw__old: 'material-components-web/dist/material-components-web.min.css',
mdc__old: '@geostreams/gltg__old/app/styles_custom/react-mdc-web.css',
coreStyle: '@geostreams/core/src/styles/core.less',
gltgStyle: './src/styles/gltg.less'
},
output: {
path: path.resolve('./build'),
publicPath: process.env.CONTEXT || '/',
filename: 'js/[name]-[chunkhash].js',
crossOriginLoading: 'anonymous'
},
optimization: {
splitChunks: {
chunks: 'all'
}
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules\/(?!(@geostreams)\/).*/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: [
'@babel/env',
'@babel/flow',
'@babel/react'
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from'
]
}
}
]
},
{
test: /\.less$/, // TODO add css after porting all the __old codes
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../'
}
},
'css-loader',
{
loader: 'less-loader',
options: {
lessOptions: {
paths: [
path.resolve('./src'),
path.resolve('./node_modules')
]
},
sourceMap: true
}
}
]
},
// TODO remove the following two rules after porting all the __old codes
{
test: /\.css$/,
include: [
/node_modules\/(?!(@geostreams)\/).*/,
/styles_custom/
],
use: [
{
loader: MiniCssExtractPlugin.loader
},
'css-loader'
]
},
{
test: /\.css$/,
exclude: [
/node_modules\/(?!(@geostreams)\/).*/,
/styles_custom/
],
use: [
{
loader: MiniCssExtractPlugin.loader
},
'css-loader?modules'
]
},
{
type: 'javascript/auto',
test: /\.geojson$/,
use: [
{
loader: 'file-loader',
options: {
name: 'files/[name]-[contenthash].[ext]'
}
}
]
},
// loader for specific json files
{
type: 'javascript/auto',
test: /data_20years\.json$/,
use: [
{
loader: 'file-loader',
options: {
name: 'files/[name]-[contenthash].[ext]'
}
}
]
},
{
test: /\.svg$/,
use: [
{
loader: 'raw-loader'
}
]
},
{
test: /\.(jpg|jpeg|png|eot|ttf|woff|woff2|pbf)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'files/[name]-[contenthash].[ext]'
}
}
]
},
{
test: /.html$/,
exclude: /.*\/index.html$/,
use: [
{
loader: 'file-loader',
options: {
name: 'pages/[name]-[contenthash].html'
}
}
]
}
]
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
'react': path.resolve('./node_modules/react'),
'redux': path.resolve('./node_modules/redux'),
'react-router-dom': path.resolve('./node_modules/react-router-dom'),
'react-redux': path.resolve('./node_modules/react-redux'),
'@material-ui': path.resolve('./node_modules/@material-ui'),
'process': path.resolve('./node_modules/process')
}
},
plugins: [
new Webpack.ProvidePlugin({
process: 'process/browser'
}),
new Webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(
dependencies['@geostreams/core']
),
'process.env.CONTEXT': JSON.stringify(process.env.CONTEXT)
}),
new HtmlWebpackPlugin({
template: path.resolve('./src/index.html'),
google_analytics: process.env.GA_TOKEN
}),
new FaviconsWebpackPlugin({
logo: './src/images/logo_app.png',
prefix: 'icons/',
emitStats: false,
inject: true
}),
new MiniCssExtractPlugin({ filename: 'css/[name]-[chunkhash].css' }),
new CleanWebpackPlugin(),
new ESLintPlugin({
emitWarning: true,
failOnError: false
})
]
};