-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
144 lines (132 loc) · 3.31 KB
/
webpack.config.js
File metadata and controls
144 lines (132 loc) · 3.31 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const SitemapPlugin = require('sitemap-webpack-plugin')
const DotenvWebpack = require('dotenv-webpack')
const isProd = process.env.NODE_ENV === 'production'
const chunkFile = isProd ? '[name].[chunkhash]' : '[name]'
const hashFile = isProd ? '[name].[hash:5]' : '[name]'
const DotenvPlugin = isProd
? new webpack.DefinePlugin({
'process.env': {
GRAPHQL_ENDPOINT: JSON.stringify(process.env.GRAPHQL_ENDPOINT),
GOOGLE_ANALYTICS: JSON.stringify(process.env.GOOGLE_ANALYTICS),
},
})
: new DotenvWebpack()
const htmlConfig = {
title: 'Gavin Anthony',
favicon: 'src/img/favicon.png',
template: 'src/index.ejs',
}
const htmlConfig404 = Object.assign({}, htmlConfig, {
filename: '404.html',
})
const routes = [
'/',
'/about',
'/contact',
'/work/recipelist',
'/work/jomo',
'/work/taplet',
'/work/blip',
'/work/likeli',
]
module.exports = {
devtool: isProd ? 'cheap-module-source-map' : 'eval-source-map',
devServer: {
contentBase: './',
stats: 'errors-only',
headers: { 'Access-Control-Allow-Origin': '*' },
},
entry: {
app: ['./src/javascripts/index.js'],
vendor: [
'axios',
'lost',
'prop-types',
'react-dom',
'react-ga',
'react-router-dom',
'react-svg-inline',
'react-tilt',
'react',
],
},
output: {
filename: `javascripts/${chunkFile}.js`,
path: path.join(__dirname, 'dist'),
publicPath: '/',
},
module: {
rules: [
{
test: /\.(js|jsx)?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(scss|sass|css)$/i,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: { minimize: true },
},
'postcss-loader',
'sass-loader',
],
}),
},
{
test: /\.(jpg|jpeg|png|gif)$/i,
use: [
{
loader: 'file-loader',
options: {
name: `[path]${hashFile}.[ext]`,
},
},
],
},
{
test: /\.(eot|ttf|woff|woff2)$/i,
use: [
{
loader: 'url-loader',
options: {
name: `[path]${chunkFile}.[ext]`,
},
},
],
},
{
test: /\.svg$/,
loader: 'raw-loader',
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.scss'],
modules: ['node_modules'],
alias: {
img: path.join(__dirname, 'src/img'),
components: path.join(__dirname, 'src/javascripts/components'),
clients: path.join(__dirname, 'src/javascripts/clients'),
pages: path.join(__dirname, 'src/javascripts/pages'),
utils: path.join(__dirname, 'src/javascripts/utils'),
},
},
plugins: [
new ExtractTextPlugin(`stylesheets/${chunkFile}.css`),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
}),
new HtmlWebpackPlugin(htmlConfig),
new HtmlWebpackPlugin(htmlConfig404),
new SitemapPlugin('https://gavinanthony.com', routes),
DotenvPlugin,
],
}