-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
149 lines (136 loc) · 3.88 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
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const src = path.join(__dirname, './src');
const buildOutputPath = path.join(__dirname, './dist');
const env = process.env.NODE_ENV || 'development';
const isProd = env === 'production';
const isDev = env === 'development';
require('dotenv').config();
function styleLoaders (loaders, extract) {
return extract ? ExtractTextPlugin.extract({
fallback: 'style-loader',
use: loaders,
publicPath: '/dist'
}) : [{ loader: 'style-loader' }].concat(loaders);
}
const config = {
entry: {
app: [
src + '/index.js'
]
},
output: {
path: buildOutputPath,
publicPath: '/',
filename: '[name].js',
chunkFilename: '[id].[hash].js'
},
devServer: {
historyApiFallback: {
hot: true,
rewrites: [
{ from: /./, to: 'index.html' },
]
},
},
plugins: [
new CleanWebpackPlugin(['./dist'], {
root: path.join(__dirname, './'),
verbose: true,
dry: false
}),
new ExtractTextPlugin({
filename: 'style.css',
disable: false,
allChunks: true
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: `'${ env }'`,
BROWSER: JSON.stringify(true),
__DEBUG__: (env !== 'production'),
FIREBASE_API_KEY: JSON.stringify(process.env.FIREBASE_API_KEY),
FIREBASE_AUTH_DOMAIN: JSON.stringify(process.env.FIREBASE_AUTH_DOMAIN),
FIREBASE_DATABASE_URL: JSON.stringify(process.env.FIREBASE_DATABASE_URL),
FIREBASE_STORAGE_BUCKET: JSON.stringify(process.env.FIREBASE_STORAGE_BUCKET),
FIREBASE_MESSAGING_SENDER_ID: JSON.stringify(process.env.FIREBASE_MESSAGING_SENDER_ID),
YOUTUBE_API_KEY: JSON.stringify(process.env.YOUTUBE_API_KEY),
}
}),
new webpack.NamedModulesPlugin()
],
resolve: {
extensions: ['.js', '.sass', '.scss'],
modules: [
src,
'node_modules'
]
},
devtool: isProd ? false : 'inline-source-map',
module: {
noParse: [
/\.DS_Store$/,
/node_modules\/method/
],
rules: [
{ test: /\.s(c|a)ss$/,
exclude: [/dist/],
use: styleLoaders([{
loader: 'css-loader?minimize'
}, {
loader: 'postcss-loader',
options: {
plugins: () => [ autoprefixer({ browsers: ['last 2 version'] }) ]
}
}, {
loader: 'sass-loader?indentedSyntax'
}], !isDev)
},
{ test: /\.css$/, loader: styleLoaders('css-loader?minimize', !isDev) },
{ test: /\.js$/, exclude: [/node_modules/, /dist/], loaders: [
'react-hot-loader/webpack',
'babel-loader?cacheDirectory=true'
] },
{ test: /\.(png|jpg|gif)$/, loader: 'file-loader?name=[path][name].[ext]?[hash]' },
{ test: /\.(woff|woff2|eot|ttf|svg)$/, loader: 'file-loader?name=fonts/[name].[ext]?[hash]?limit=100000' },
{ test: /\.html$/, loader: 'html-loader' }
]
}
};
if (isProd) {
// Add UglifyJS
config.plugins = config.plugins.concat([
// Stop modules with syntax errors from being emitted.
new webpack.optimize.UglifyJsPlugin({
minimize: true,
sourceMap: true,
mangle: false,
removeRedundantAttributes: false,
compress: {
dead_code: true,
drop_console: true
},
compressor: {
warnings: false
},
output: {
comments: false
}
}),
new webpack.optimize.AggressiveMergingPlugin(),
]);
} else {
config.entry.app = [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080'
].concat(config.entry.app);
config.plugins = config.plugins.concat([
new webpack.LoaderOptionsPlugin({
debug: true
})
]);
}
module.exports = config;