This repository has been archived by the owner on Oct 2, 2018. It is now read-only.
forked from hkoscon/2017
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
120 lines (110 loc) · 3.14 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
'use strict';
require('dotenv').load();
const webpack = require('webpack');
const UglifyPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const AggressiveMergingPlugin = require('webpack/lib/optimize/AggressiveMergingPlugin');
const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin');
const PrecachePlugin = require('sw-precache-webpack-plugin');
const merge = require('webpack-merge');
const manifest = require('./manifest.json');
const firebaseConfig = {
FIREBASE_API_KEY: JSON.stringify(process.env.FIREBASE_API_KEY || '<API_KEY>'),
FIREBASE_AUTH_DOMAIN: JSON.stringify(process.env.FIREBASE_AUTH_DOMAIN || '<PROJECT_ID>.firebaseapp.com'),
FIREBASE_DATEBASE_URL: JSON.stringify(process.env.FIREBASE_DATEBASE_URL || 'https://<DATABASE_NAME>.firebaseio.com'),
FIREBASE_STORAGE_BUCKET: JSON.stringify(process.env.FIREBASE_STORAGE_BUCKET || '<BUCKET>.appspot.com'),
FIREBASE_MESSAGING_SENDER_ID: JSON.stringify(process.env.FIREBASE_MESSAGING_SENDER_ID || '<SENDER_ID>'),
FIREBASE_MESSAGE_SERVER_KEY: JSON.stringify(process.env.FIREBASE_MESSAGE_SERVER_KEY || '<SENDER_KEY>'),
};
const envConfig = {};
Object.keys(firebaseConfig).forEach((key) => {
envConfig[`process.env.${key}`] = firebaseConfig[key];
});
const base = {
plugins: [
new AggressiveMergingPlugin(),
new webpack.DefinePlugin(envConfig),
new PrecachePlugin({
cacheId: 'HKOSCon-2017',
minify: true,
filename: 'sw.js',
handleFetch: true,
runtimeCaching: [{
urlPattern: /2017/,
handler: 'fastest',
}],
staticFileGlobs: manifest.web_accessible_resources.map(path => path.replace('/2017', 'public')),
stripPrefix: 'public',
verbose: true,
}),
],
externals: {
jquery: 'jQuery',
hammerjs: 'Hammer',
'node-waves': 'Waves',
firebase: 'firebase',
react: 'React',
'react-dom': 'ReactDOM',
redux: 'Redux',
'react-redux': 'ReactRedux',
'moment-timezone': 'moment',
toastr: 'toastr',
},
entry: {
app: ['./assets/js/app'],
timetable: ['./assets/js/timetable'],
venue: ['./assets/js/venue'],
staff: ['./assets/js/pages/staff'],
},
devtool: 'source-map',
output: {
path: `${__dirname}/public`,
publicPath: '/2017/',
filename: '[name].js',
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{ test: /\.js$/, use: ['babel-loader'] },
{ test: /\.jsx$/, use: ['babel-loader'] },
],
},
};
const dev = merge.smart({
plugins: [
new HotModuleReplacementPlugin(),
],
entry: {
app: [
'webpack-dev-server/client?http://localhost:8080/',
],
timetable: [
'webpack-dev-server/client?http://localhost:8080/',
],
venue: [
'webpack-dev-server/client?http://localhost:8080/',
],
},
module: {
loaders: [
{ test: /\.jsx$/, use: ['react-hot'] },
],
},
}, base);
const production = merge.smart({
plugins: [
new UglifyPlugin({
minimize: true,
sourceMap: true,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
}, base);
module.exports = {
base,
dev,
production,
};