This repository has been archived by the owner on Jul 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
webpack.config.js
150 lines (131 loc) · 4.01 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
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
145
146
147
148
149
150
const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const DashboardPlugin = require('webpack-dashboard/plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const production = process.env.NODE_ENV === 'production';
const pagesBuild = process.env.BUILD === 'pages';
/*********************************** Loaders ***********************************/
const loaders = [
{ // react-hot is implemented as babel plugin now
test: /\.(js|jsx)$/,
loader: 'babel',
include: path.join(__dirname, 'src'),
exclude: /node_modules/,
},
{ // used for all project files and some dependencies
test: /\.scss$/,
loader: production
? ExtractTextPlugin.extract(['css', 'postcss', 'sass', 'sass-resources'])
: ['style', 'css?sourceMap', 'postcss', 'sass?sourceMap', 'sass-resources'].join('!'),
include: path.join(__dirname, 'src'),
},
{ // used for dependencies that don't support sass
test: /\.css$/,
loaders: ['style', 'css', 'postcss'],
},
{ // svg sprites generated only for icons
test: /\.svg$/,
loader: `svg-sprite?${JSON.stringify({ name: '[hash]', prefixize: true })}`,
include: path.join(__dirname, 'src/ui/Icon'),
},
{ // other svg images will processed as normal
test: /\.svg$/,
loader: 'file',
include: path.join(__dirname, 'src'),
exclude: path.join(__dirname, 'src/ui/Icon'),
},
];
// Plugins used in all builds
const pluginsBase = [
new HtmlWebpackPlugin({
title: 'Colorizr',
template: 'template.ejs',
}),
new FaviconsWebpackPlugin({
logo: './favicon.png',
background: '#ffeeee',
icons: {
android: false,
appleIcon: false,
appleStartup: false,
coast: false,
favicons: true,
firefox: false,
opengraph: false,
twitter: false,
yandex: false,
windows: false,
},
}),
new webpack.DefinePlugin({
'process.env': { // build is used for gh-pages
NODE_ENV: JSON.stringify(process.env.NODE_ENV || ''),
BUILD: JSON.stringify(process.env.BUILD || ''),
},
}),
];
const developmentPlugins = [
...pluginsBase,
new BundleAnalyzerPlugin({ analyzerPort: 3004, openAnalyzer: false }),
new DashboardPlugin({ port: 3005 }),
new webpack.HotModuleReplacementPlugin(),
];
const productionPlugins = [
...pluginsBase,
new ExtractTextPlugin('style.css'),
new LodashModuleReplacementPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
comments: false,
compress: {
sequences: true,
booleans: true,
loops: true,
unused: false,
warnings: false,
drop_console: true,
unsafe: true,
},
}),
];
module.exports.loaders = loaders;
module.exports.plugins = {
base: pluginsBase,
development: developmentPlugins,
production: productionPlugins,
};
module.exports = {
devtool: production ? 'cheap-module-source-map' : 'eval',
entry: production
? ['babel-polyfill', './src/index']
: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3002',
'webpack/hot/only-dev-server',
'babel-polyfill',
'./src/index',
],
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js',
publicPath: pagesBuild ? '/react-challenge-colorizr' : '/',
},
resolve: {
root: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules'),
],
extensions: ['', '.js', '.jsx'],
},
module: { loaders },
plugins: production ? productionPlugins : developmentPlugins,
sassResources: './src/styles/resources/**/*.scss',
postcss: [autoprefixer({ browsers: ['last 4 versions'] })],
};