-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
90 lines (82 loc) · 2.07 KB
/
webpack.config.js
File metadata and controls
90 lines (82 loc) · 2.07 KB
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
/**
* @file webpack.config.js
* Contains Webpack build configuration.
*/
const dns = require('dns');
const os = require('os');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const NODE_ENV_PRODUCTION = 'production';
const NODE_ENV_DEVELOPMENT = 'development';
const NODE_ENV = process.env.NODE_ENV ? process.env.NODE_ENV.toLowerCase() : NODE_ENV_DEVELOPMENT;
const DEVELOPMENT_SERVER_IP = process.env.DEVELOPMENT_SERVER_IP || false;
const DEVELOPMENT_SERVER_PORT = process.env.DEVELOPMENT_SERVER_PORT || false;
// Construct plugins array.
const plugins = [];
plugins.push(new HtmlWebpackPlugin({
template: 'src/index.html',
inject: 'body',
filename: 'index.html',
}));
if (NODE_ENV === NODE_ENV_PRODUCTION) {
plugins.push(new FaviconsWebpackPlugin({
logo: './src/assets/images/logo.png',
inject: true,
}));
}
// Configure loaders.
const loaders = [
{
test: /\.js|jsx$/,
exclude: /node_modules/,
loaders: ['babel-loader'],
},
{
test: /\.(jpe?g|png|gif|svg|mp3)$/i,
loaders: ['file-loader'],
},
{
test: /\.(dae)$/i,
loaders: ['file-loader'],
},
];
/**
* Fetches and resolves this machine's IP address.
*
* @returns {Promise<String>}
* Promise that resolves this machine's IP address.
*/
const fetchIp = () => (
new Promise((resolve, reject) => {
if (DEVELOPMENT_SERVER_IP) {
resolve(DEVELOPMENT_SERVER_IP);
} else {
dns.lookup(os.hostname(), (error, address) => (error ? reject(error) : resolve(address)));
}
})
);
// Calculate the build destination.
let dest = `${__dirname}/dist`;
if (process.env.NODE_ENV === NODE_ENV_PRODUCTION) {
dest = __dirname;
}
module.exports = () => (
fetchIp().then(host => ({
entry: './src/index.jsx',
output: {
path: dest,
filename: 'drupalcon-vr.[hash].js',
publicPath: '',
},
module: {
loaders,
},
devServer: {
host,
port: DEVELOPMENT_SERVER_PORT || '8080',
},
plugins,
})).catch((error) => {
throw new Error(error);
})
);