-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
187 lines (181 loc) · 6.26 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
//On the command line we just need to call webpack
// which will use this config to build app.jsx and dependencies into bundle.js,
// having babel convert our jsx into js through react.
var webpack = require('webpack');
var path = require('path');
var envFile = require('node-env-file');
const {GenerateSW} = require('workbox-webpack-plugin');
// For Workbox plugin, for ServiceWorkers
const DIST_DIR = 'public';
// Will be 'production' on heroku, but missing locallaly so we'll set to 'development'
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
// Load the relevant environment vars from the config folder, (if the file exists)
envFile(path.join(__dirname, `config/${process.env.NODE_ENV}.env`), {raise: false});
// For replacing strings within the content at build time
const properties = require(path.join(__dirname, 'app/config/properties.json'));
const StringReplacePlugin = require('string-replace-webpack-plugin');
const string_replacement_loader = StringReplacePlugin.replace({
replacements: [
{
pattern: /\{-{(.*)}-}/g,
replacement: function (match, p1, offset, string) {
return eval(`properties.${p1}`);
}
}
]});
module.exports = {
entry: [
'babel-polyfill',
//Where script-loader!, (or style! or css! etc.) are used, that means use a loader, (e.g. script-loader module,) to pull in these files.
'script-loader!jquery/dist/jquery.min.js',
'script-loader!foundation-sites/dist/js/foundation.min.js',
'./app/app.jsx'
],
externals: {
jquery: 'jQuery'
},
plugins: [
//If webpack finds reference to $ or jQuery in our code, load in the jquery module.
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery'
}),
new webpack.DefinePlugin({
// A common mistake is not stringifying the "production" string, to save doing the lookup in prod
//'process.env.NODE_ENV': JSON.stringify('production')
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
FIREBASE_SERVICE_PROJECT_ID: JSON.stringify(process.env.FIREBASE_SERVICE_PROJECT_ID),
FIREBASE_SERVICE_PRIVATE_KEY_ID: JSON.stringify(process.env.FIREBASE_SERVICE_PRIVATE_KEY_ID),
FIREBASE_SERVICE_PRIVATE_KEY: JSON.stringify(process.env.FIREBASE_SERVICE_PRIVATE_KEY),
FIREBASE_SERVICE_CLIENT_EMAIL: JSON.stringify(process.env.FIREBASE_SERVICE_CLIENT_EMAIL),
FIREBASE_SERVICE_CLIENT_ID: JSON.stringify(process.env.FIREBASE_SERVICE_CLIENT_ID),
FIREBASE_SERVICE_AUTH_URI: JSON.stringify(process.env.FIREBASE_SERVICE_AUTH_URI),
FIREBASE_SERVICE_TOKEN_URI: JSON.stringify(process.env.FIREBASE_SERVICE_TOKEN_URI),
FIREBASE_SERVICE_AUTH_PROVIDER_X509_CERT_URL: JSON.stringify(process.env.FIREBASE_SERVICE_AUTH_PROVIDER_X509_CERT_URL),
FIREBASE_SERVICE_CLIENT_X509_CERT_URL: JSON.stringify(process.env.FIREBASE_SERVICE_CLIENT_X509_CERT_URL),
GOOGLE_CLOUD_STORAGE_BUCKET: JSON.stringify(process.env.GOOGLE_CLOUD_STORAGE_BUCKET),
AUTH_SECRET: JSON.stringify(process.env.AUTH_SECRET),
AUTH_USERNAME: JSON.stringify(process.env.AUTH_USERNAME),
AUTH_PASSWORD: JSON.stringify(process.env.AUTH_PASSWORD),
LEAGUE_TABLE_URL: JSON.stringify(process.env.LEAGUE_TABLE_URL)
}
}),
new StringReplacePlugin(),
new GenerateSW({
swDest: 'sw.js',
runtimeCaching: [
{
urlPattern: /\.js$/,
handler: 'CacheFirst',
}
]
})
],
output: {
path: path.resolve(__dirname, DIST_DIR),
filename: 'bundle.js'
},
resolve: {
modules: [
__dirname,
'node_modules',
'./app/components/',
'./app/api/'
],
alias: {
//The resolve.alias settings means we can just require <name> rather than './component/<name>'
app: path.resolve(__dirname, 'app/'), // This one lets you import anything as 'app/<folder>/<file>'
applicationStyles: path.resolve(__dirname, 'app/styles/app.scss'),
actions: path.resolve(__dirname, 'app/actions/actions.jsx'),
reducers: path.resolve(__dirname, 'app/reducers/reducers.jsx'),
configureStore: path.resolve(__dirname, 'app/store/configureStore.jsx')
},
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
//rules.test is a regex to see which files this loader should apply to.
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0']
}
},
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
use: [
string_replacement_loader
]
},
{
test: /\.scss$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
},
{
loader: "sass-loader",
options: {
sassOptions: {
includePaths: [path.resolve(__dirname, './node_modules/foundation-sites/scss')]
}
}
},
{
loader: string_replacement_loader
}
]
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
// {
// loader: 'sass-loader'
// },
{
loader: string_replacement_loader
}
]
},
{
test: /\.(png|jpg|jpeg|gif)$/,
loader: 'url-loader'
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [
{
loader: "url-loader",
options: {
limit: 10000,
mimetype: "application/font-woff"
}
}
]
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "file-loader"
}
]
},
//'eval-source-map' lets us debug the code as written, rather than in bundle.js.
// Only applies during development, since it is a devtool setting.
devtool: process.env.NODE_ENV === 'production' ? undefined : 'cheap-module-eval-source-map'
}