-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebpack.config.js
65 lines (61 loc) · 1.76 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
'use strict'
const path = require('path')
const webpack = require('webpack')
const HtmlPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CleanPlugin = require('clean-webpack-plugin')
const precss = require('precss')
const autoprefixer = require('autoprefixer')
const postcssImport = require('postcss-import')
const production = process.env.NODE_ENV === 'production'
const theme = process.env.SALESFORCE_THEME === 'true' ? 'salesforce' : 'heroku'
const html = (filename, bodyClass, title = 'Kafka Demo App') => new HtmlPlugin({
production,
filename,
bodyClass,
title,
inject: false,
template: path.join(__dirname, 'views', 'index.pug')
})
module.exports = {
entry: path.join(__dirname, 'src', 'index.js'),
output: {
path: path.join(__dirname, 'dist'),
filename: `app${production ? '.[hash]' : ''}.js`
},
module: {
loaders: [
{
test: /.js$/,
loader: 'babel',
exclude: /node_modules/
},
{
test: /.json$/,
loader: 'json'
},
{
test: /.pug$/,
loader: 'pug'
},
{
test: /\.css$/,
loader: production ? ExtractTextPlugin.extract('style', 'css!postcss') : 'style!css!postcss'
}
]
},
postcss: (webpack) => [
postcssImport({ addDependencyTo: webpack }),
precss,
autoprefixer
],
plugins: [
html('index.html', theme),
new CleanPlugin(['dist'], { root: __dirname, verbose: false }),
new webpack.DefinePlugin({
'process.env': { TWITTER_TRACK_TERMS: JSON.stringify(process.env.TWITTER_TRACK_TERMS) }
}),
production && new ExtractTextPlugin('app.[contenthash].css'),
!production && new (require('webpack-livereload-plugin'))()
].filter(Boolean)
}