This repository has been archived by the owner on Dec 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
126 lines (109 loc) · 2.96 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
/* eslint-env node */
/* eslint no-var:0 */
var path = require('path')
var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
require('dotenv').load()
var config = require('./webpack/config')
var srcPath = path.resolve('./src')
var proxyMatch = config.SIRIUS_PROXY_PATH + '/**'
var definePlugin = new webpack.DefinePlugin({
// Remember this will get replaced with literal contents of string, so we need extra quotes
'process.env.NODE_ENV': JSON.stringify(config.NODE_ENV),
'process.env.FITTABLE_SOURCE': JSON.stringify(config.FITTABLE_SOURCE),
'process.env.SIRIUS_PROXY_PATH': JSON.stringify(config.SIRIUS_PROXY_PATH),
'process.env.SENTRY_DSN': JSON.stringify(config.SENTRY_DSN),
})
var sassLoader = '!sass?' +
'includePaths[]=' +
(path.resolve(__dirname, './node_modules/foundation-sites/scss')) +
'&' +
'includePaths[]=' +
(path.resolve(__dirname, './node_modules'))
// webpack-dev-server extension
var ENV_COOKIES = {
/* eslint camelcase:0 */
oauth_access_token: process.env.OAUTH_ACCESS_TOKEN,
oauth_username: process.env.OAUTH_USERNAME,
}
function setCookiesMiddleware (req, res, next) {
for (var name in ENV_COOKIES) {
var value = ENV_COOKIES[name]
res.cookie(name, value, {httpOnly: false})
}
next()
}
function rewriteUrl (replacePath) {
return function (req, opt) {
var queryIdx = req.url.indexOf('?')
var query = queryIdx >= 0 ? req.url.substr(queryIdx) : ''
req.url = req.path.replace(opt.path, replacePath) + query
req.headers['Authorization'] = 'Bearer ' + ENV_COOKIES.oauth_access_token
console.log('proxying:', req.originalUrl, '->', req.url)
}
}
module.exports = {
entry: {
js: srcPath + '/app.js',
css: srcPath + '/stylesheets/fittable.scss',
},
output: {
filename: 'fittable.js',
path: path.resolve('./dist'),
},
plugins: [
definePlugin,
new ExtractTextPlugin('fittable.css', {
allChunks: true,
}),
],
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
include: srcPath,
},
{
test: /\.json$/,
loader: 'json',
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style-loader', 'css!autoprefixer' + sassLoader + ''),
},
{
test: /\.(jpg|png)$/,
loader: 'file',
},
],
},
resolve: {
alias: {
'react': path.join(__dirname, 'node_modules', 'react'),
},
extensions: ['', '.jsx', '.js'],
},
stats: {
colors: true,
},
devServer: {
hot: true,
inline: true,
lazy: false,
historyApiFallback: true,
contentBase: 'dist/',
setup: function (app) {
app.use(setCookiesMiddleware)
},
proxy: [
{
path: proxyMatch,
rewrite: rewriteUrl('$1'),
target: config.SIRIUS_UPSTREAM_URL,
changeOrigin: true, // set proper Host of the target
secure: false, // do not validate certificates
},
],
},
}