This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
webpack.config.js
254 lines (248 loc) · 6.91 KB
/
webpack.config.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
/**
* Webpack config for the project
*
* This file tells webpack how to build your project, and includes instructions for both development and production
* environments. For an understanding of what each setting is for, see the official webpack documentation:
*
* https://webpack.js.org/configuration/
*
* If you're new to webpack, you may find this video series by Kent Dodds helpful for getting up to speed quickly:
* https://egghead.io/courses/using-webpack-for-production-javascript-applications
**/
var pkg = require('./package.json');
var path = require('path');
var webpack = require('webpack');
var ProgressBarPlugin = require('progress-bar-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var { getIfUtils, removeEmpty, propIf } = require('webpack-config-utils');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var BundleTracker = require('webpack-bundle-tracker');
var fs = require('fs');
// Theme Images
var themeImagesPath = require('./themeImagesPath');
module.exports = function(ENV) {
var { ifProduction } = getIfUtils(ENV);
// Preface the webpack-dev-server command with CSS_IN_JS=true for CSS hot
// reloading.
//
// By default we extract CSS from the larger bundle into a separate asset
// that is parsed/loaded before any js, this ensures that the content of our
// html will be styled the first time it is shown. However, CSS hot
// reloading only works if the CSS is shipped in the JS.
var extractCSS = ifProduction(true, !process.env.CSS_IN_JS);
var PATHS = {
output: path.join(__dirname, "/troposphere/assets/bundles"),
context: path.join(__dirname, "/troposphere/static/js/"),
css: path.join(__dirname, "/troposphere/static/css/"),
images: path.join(__dirname, "/troposphere/static/images/"),
theme: path.join(__dirname, "/troposphere/static/theme/"),
themeImages: themeImagesPath,
public: "/assets/bundles/"
};
return {
devtool: ifProduction('source-map', 'eval'),
entry: removeEmpty({
vendor: Object.keys(pkg.dependencies),
app: "./main",
analytics: "./analytics",
public: "./public_site/main"
}),
output: {
filename: ifProduction(
'bundle.[name].[chunkhash].js',
'bundle.[name].js'
),
path: PATHS.output,
pathinfo: ifProduction(false, true),
publicPath: PATHS.public
},
context: PATHS.context,
resolve: {
alias: {
react: path.resolve(__dirname, 'node_modules/react'),
highcharts: "highcharts-commonjs",
css: PATHS.css,
images: PATHS.images,
theme: PATHS.theme,
themeImages: PATHS.themeImages
},
modules: [
PATHS.context,
"node_modules"
],
extensions: [".js", ".jsx", ".scss", ".sass"]
},
module: {
rules: [
{
test: /bootstrap-sass/,
use: [
"imports-loader?jQuery=jquery"
]
},
{
test: /modernizr-latest\.js/,
use: [
"imports-loader?this=>window,html5=>window.html5",
"exports-loader?window.Modernizr"
]
},
{
test: /\.js$/,
use: 'babel-loader',
// exclude: /node_modules/
exclude: /(node_modules|troposphere\/static\/js\/lib)/
},
{
test: /\.jsx$/,
use: 'babel-loader',
// exclude: /node_modules/
exclude: /(node_modules|troposphere\/static\/js\/lib)/
},
{
test: /\.css/,
use: propIf(extractCSS, ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader'
]
}), [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader'
])
},
{
test: /\.less$/,
use: propIf(extractCSS, ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader',
'less-loader'
]
}), [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader',
'less-loader'
])
},
{
test: /\.scss$/,
use: propIf(extractCSS, ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader',
'sass-loader'
]
}), [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader',
'sass-loader'
])
},
{
test: /\.(png|jpg|jpeg|gif|tif|tiff|bmp|svg)$/,
use: {
loader: 'url-loader',
options: {
// limit: 10000,
limit: 10,
name: ifProduction(
'assets/images/[name].[hash:8].[ext]',
'assets/images/[name].[ext]'
)
}
}
},
{
test: /\.(ttf|otf|eot|woff(2)?)(\?[a-z0-9]+)?$/,
use: {
loader: 'file-loader',
options: {
name: ifProduction(
'assets/fonts/[name].[hash:8].[ext]',
'assets/fonts/[name].[ext]'
)
}
}
},
{
test: /\.json/,
use: 'json-loader'
}
]
},
plugins: removeEmpty([
new BundleTracker({
filename: './webpack-stats.json'
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(ENV)
}
}),
new ProgressBarPlugin(),
new ExtractTextPlugin(ifProduction(
'styles.[name].[chunkhash].css',
'styles.[name].css'
)),
new webpack.optimize.CommonsChunkPlugin({
names: [
'vendor',
'manifest'
],
minChunks: Infinity
}),
new CopyWebpackPlugin([
{
from: PATHS.themeImages,
to: "theme/images"
},
{
from: PATHS.theme + "/login.css",
to: "theme/login.css"
}
])
]),
devServer: {
headers: {
"Access-Control-Allow-Origin": "*"
},
}
};
};