-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
77 lines (68 loc) · 1.82 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
const { resolve, join } = require('path')
const webpack = require('webpack')
const path = require('path')
const fs = require('fs')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const babelSettings = JSON.parse(fs.readFileSync(".babelrc"))
if (!process.env.NODE_ENV) {
console.error('Oopz! Variable "NODE_ENV" not found!')
return false
}
if (!process.env.API_URL) {
console.error('Oopz! Variable "API_URL" not found!')
return false
}
const __SRC__ = resolve(__dirname, 'src')
const __PRODUCTION__ = process.env.NODE_ENV === 'production'
const __DEVELOPMENT__ = ! __PRODUCTION__
const __API_URL__ = process.env.API_URL
const __PORT__ = process.env.PORT || 8080
const config = {
context: __SRC__,
cache: true,
watch: true,
resolve: {
extensions: ['.js', '.jsx']
},
entry: [],
output: {
path: resolve(__dirname, 'public'),
publicPath: '/',
filename: 'bundle.js'
},
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: process.env.NODE_ENV,
PORT: __PORT__,
API_URL: __API_URL__
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new ExtractTextPlugin('styles.css')
],
module: {
rules: [
{
test: /\.jsx?$/,
use: ['babel-loader'],
exclude: /node_modules/,
include: join(__dirname, 'src')
},{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
},{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?.*)?$/,
use: 'file-loader'
}
]
}
}
if (__DEVELOPMENT__) {
module.exports = require('./webpack.development')(webpack, config, __PORT__)
}
if (__PRODUCTION__) {
module.exports = require('./webpack.production')(webpack, config)
}