-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
76 lines (74 loc) · 2.26 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
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
// All the vendor libs that only need to be update once
const VENDOR_LIBS = [
'react', 'redux', 'react-redux', 'react-dom', 'redux-thunk'
];
module.exports = {
entry: {
bundle: './src/index.js',
vendor: VENDOR_LIBS,
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].[chunkhash].js',
// add public path for url loader to find new path of build images
// it will prepend build/{hashedimaged}.jpg to import big from 'assets/big.jpg'
},
module: {
rules: [
{
use: 'babel-loader',
test: /\.js$/,
// Do not try to use babel on node_modules, not needed
exclude: /node_modules/,
},
{
// order is important, read from right to left
// use: ['style-loader','css-loader'],
// nasty way to use ExtractTextPlugin with webpack 1.0
loader: ExtractTextPlugin.extract({
loader: 'css-loader'
}),
// process only .css files
test: /\.css$/,
},
{
use: [
// need to pass new config to url-loader(big or small files)
{
loader: 'url-loader',
options: { limit: 40000 },
},
'image-webpack-loader',
],
// e? <- wether with e or not will do
test: /\.(jpe?g|png|gif|svg)$/,
},
],
},
plugins: [
// Use of CommonsChunkPlugin.
// pluck vendor from bundle.js and add to vendor entry point.
// Use names to add manifest to deal with cache files
// check out dist/index.html
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
}),
// For generate script tag in index.html for all entry js
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
// Combine all css file to this style.css
new ExtractTextPlugin('style.css'),
new CopyWebpackPlugin([{
from: path.join(__dirname, './src/assets'),
}]),
],
};