-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
97 lines (88 loc) · 2.84 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
const ENV = process.env.NODE_ENV || 'development'
const TARGET = process.env.npm_lifecycle_event
require('dotenv').config({path: `.env.${ENV}`}) // Load .env
const webpack = require('webpack')
const path = require('path')
const merge = require('webpack-merge')
const HtmlwebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ROOT_PATH = path.resolve(__dirname)
const APP_PATH = path.resolve(ROOT_PATH, 'app/js')
const APP_PATH_ENTRY = APP_PATH + '/app.jsx'
const BUILD_PATH = path.resolve(ROOT_PATH, 'dist')
const STYLES_PATH = path.resolve(ROOT_PATH, 'app/styles')
const TEMPLATES_PATH = path.resolve(ROOT_PATH, 'app/views')
const cssExtract = new ExtractTextPlugin('analytics.css')
const CLIENT_PORTAL_ASSETS_PATH = path.resolve(ROOT_PATH, 'node_modules/client_portal-assets')
// Config object with values read from .env file
const envConfig = require('./envConfig.js').envConfig
const common = {
entry: ['whatwg-fetch', 'babel-polyfill', APP_PATH_ENTRY],
output: {
path: BUILD_PATH,
publicPath: process.env.PUBLIC_PATH_URL,
filename: 'analytics.js',
},
module: {
preLoaders: [
{ test: /\.jsx?$/, loaders: ['eslint'], include: APP_PATH },
],
loaders: [
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.jsx?/, include: APP_PATH, loader: 'babel' },
{
test: /\.scss$/,
loader: cssExtract.extract('style-loader', 'css-loader!postcss-loader!resolve-url-loader!sass-loader?sourceMap'),
include: [APP_PATH, STYLES_PATH, CLIENT_PORTAL_ASSETS_PATH],
},
{ test: /\.(jpe?g|png|gif)$/, loader: 'url-loader?limit=1', include: CLIENT_PORTAL_ASSETS_PATH },
{ test: /\.(woff2|woff|ttf|eot|svg)$/, loader: 'file-loader', include: [APP_PATH, CLIENT_PORTAL_ASSETS_PATH] },
],
},
plugins: [
new webpack.DefinePlugin({
CONFIG: envConfig,
}),
cssExtract,
new HtmlwebpackPlugin({
filename: 'index.html',
title: 'Awesome Analytics app',
template: TEMPLATES_PATH + '/index.html',
tableauUrl: `${process.env.TABLEAU_HOST}javascripts/api/tableau-2.js`,
}),
],
resolve: {
extensions: ['', '.js', '.jsx'],
},
externals: {
'tableau': 'tableau',
},
eslint: {
failOnWarning: true,
failOnError: true,
},
devServer: {
host: '0.0.0.0',
},
}
let webpackConfig = {}
if (TARGET === 'start' || !TARGET) {
webpackConfig = merge(common, {
devtool: 'eval-source-map',
})
} else {
webpackConfig = merge(common, {
bail: true,
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': {
// This affects react lib size
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }),
],
})
}
module.exports = webpackConfig