-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
145 lines (129 loc) · 3.8 KB
/
webpack.config.js
File metadata and controls
145 lines (129 loc) · 3.8 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
145
const path = require('path');
const webpack = require('webpack');
const AssetsPlugin = require('assets-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const WriteFilePlugin = require('write-file-webpack-plugin');
const config = require('./project.config.js');
const pkg = require('./package.json');
const babelConfig = Object.assign({}, pkg.babel, {
babelrc: false,
cacheDirectory: true,
});
let jsUse = [
{
loader: `babel-loader?${JSON.stringify(babelConfig)}`
}
];
if(config.isDevelopment) jsUse.push({
loader: 'webpack-module-hot-accept'
})
const webpackConfig = {
// The base directory for resolving the entry option
context: config.src,
// The entry point for the bundle
entry: config.js.src,
// Options affecting the output of the compilation
output: {
path: config.js.dist,
publicPath: config.publicPath,
// filename: config.isDevelopment ? 'bundle.js?[hash]' : 'bundle.[hash].js',
filename: config.js.concat,
// chunkFilename: config.isDevelopment ? '[id].js?[chunkhash]' : '[id].[chunkhash].js',
chunkFilename: '[id].js',
sourcePrefix: ' ',
},
resolve: {
modules: [
config.src,
config.components,
config.css.dir,
"node_modules"
],
extensions: [".jsx", ".js", ".json"]
},
// Switch loaders to debug or release mode
// debug: config.isDevelopment,
// Developer tool to enhance debugging, source maps
// http://webpack.github.io/docs/configuration.html#devtool
devtool: config.isDevelopment ? 'inline-source-map' : false,
// What information should be printed to the console
stats: {
colors: true,
reasons: false,
hash: false,
version: false,
timings: true,
chunks: false,
chunkModules: false,
cached: false,
cachedAssets: false,
},
// The list of plugins for Webpack compiler
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': config.isDevelopment ? '"development"' : '"production"',
__DEV__: config.isDevelopment,
}),
// Emit a JSON file with assets paths
// https://github.com/sporto/assets-webpack-plugin#options
// new AssetsPlugin({
// path: config.js.dist,
// filename: 'assets.json',
// prettyPrint: true,
// update: true
// }),
new WriteFilePlugin({
test: /\.css$/,
log: false
}),
new ExtractTextPlugin(config.css.concatWebpack)
],
module: {
rules: [
{
test: /\.jsx?$/,
use: jsUse,
exclude: /node_modules/
},
{
test: /\.(svg|jpg|jpeg|png)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
}
}
]
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: 'css-loader',
options: {
url: false,
sourceMap: config.isDevelopment,
importLoaders: 1
}
},
'postcss-loader'
]
})
}
],
}
};
if (config.isDevelopment) {
babelConfig.plugins.unshift('react-hot-loader/babel');
webpackConfig.entry.unshift('react-hot-loader/patch', 'webpack-hot-middleware/client?overlay=false&reload=true&noInfo=true');
webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
webpackConfig.plugins.push(new webpack.NoEmitOnErrorsPlugin());
} else {
webpackConfig.plugins.push(new webpack.optimize.AggressiveMergingPlugin());
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({ compress: { warnings: config.isVerbose } }));
}
module.exports = webpackConfig;