-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.config.js
executable file
·132 lines (127 loc) · 4.14 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
'use strict';
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const argv = require('minimist')(process.argv.slice(2));
const port = argv.port || '3000';
function getConfig() {
const plugins = [
new HtmlWebpackPlugin({
template: 'app/index.tpl.html',
inject: 'body',
filename: 'index.html'
}),
new FaviconsWebpackPlugin({
// Your source logo
logo: 'resources/img/favicon.png',
// The prefix for all image files (might be a folder or a name)
prefix: 'icons-[hash]/',
// Emit all stats of the generated icons
emitStats: false,
// The name of the json containing all favicon information
statsFilename: 'iconstats-[hash].json',
// Generate a cache file with control hashes and
// don't rebuild the favicons until those hashes change
persistentCache: true,
// Inject the html into the html-webpack-plugin
inject: true,
// favicon background color (see https://github.com/haydenbleasel/favicons#usage)
background: '#fff',
// favicon app title (see https://github.com/haydenbleasel/favicons#usage)
title: 'Network Statistics',
// which icons should be generated (see https://github.com/haydenbleasel/favicons#usage)
icons: {
android: true,
appleIcon: true,
appleStartup: true,
coast: false,
favicons: true,
firefox: true,
opengraph: false,
twitter: false,
yandex: false,
windows: false
}
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
];
return {
mode: 'development',
devtool: 'eval-source-map',
entry: [
'webpack-dev-server/client?http://localhost:' + port,
'webpack/hot/only-dev-server',
'react-hot-loader/patch',
path.join(__dirname, 'app/index.js')
],
plugins: plugins,
output: {
path: path.join(__dirname, '/dist/'),
filename: '[name].js',
publicPath: '/'
},
resolve: {
modules: [__dirname, 'app', 'node_modules'],
},
externals: {
config: 'config'
},
module: {
rules: [
// rules for modules (configure loaders, parser options, etc.)
{
// The file-loader handles all assets unless explicitly excluded. It makes sure
// those assets get served by WebpackDevServer.
exclude: [/\.html$/, /\.(js|jsx)$/, /\.css$/, /\.less$/, /\.scss$/,
/\.json$/, /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('file-loader'),
options: {
name: 'resources/media/[name].[hash:8].[ext]',
},
},
{
// url-loader works like file-loader except that it embeds assets smaller than specified
// limit in bytes as data URLs to avoid requests.
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'resources/media/[name].[hash:8].[ext]',
},
},
{
// Process JS with Babel.
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: /app/,
loader: require.resolve('babel-loader'),
options: {
// Cache results in ./node_modules/.cache/babel-loader/ directory for faster rebuilds
cacheDirectory: true,
},
},
{
// Resolves styles, turns CSS into JS modules that inject style tags, compiles less or sass
test: [/\.css$/, /\.less$/, /\.scss$/],
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
url: true,
},
},
require.resolve('sass-loader'),
],
},
]
}
}
}
module.exports = getConfig();