-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·128 lines (119 loc) · 3.07 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
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const BUILD_DIR = path.resolve(__dirname, 'build');
const APP_DIR = path.resolve(__dirname, 'src');
const STATIC_DIR = path.resolve(__dirname, 'static');
const DEV_PORT = '8080';
const config = {
entry: {
index: `${APP_DIR}/index.jsx`
},
output: {
path: BUILD_DIR,
filename: '[name].[hash].js',
publicPath: '/',
},
plugins: [
new CleanWebpackPlugin([BUILD_DIR]),
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV) }
}),
new HtmlWebpackPlugin({
template: `${APP_DIR}/index.html`,
filename: `${BUILD_DIR}/index.html`,
}),
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
minChunks: module => {
// This prevents stylesheet resources with the .css or .scss extension
// from being moved from their original chunk to the vendor chunk
if(module.resource && (/^.*\.(css|scss)$/).test(module.resource)) {
return false;
}
return module.context && module.context.includes("node_modules");
}
}),
new CopyWebpackPlugin([
{ from: STATIC_DIR, BUILD_DIR }
])
],
module: {
rules: [
{
include: APP_DIR,
exclude: /(node_modules)/,
test: /\.(js|jsx)$/,
loader: 'babel-loader',
query: {
presets: [ 'es2015', 'react', 'stage-2' ]
}
},
{
test: /\.(png|jpg|gif)$/,
loader: 'url-loader'
}
]
},
/* Some linux distibutions seem to have a problem without poll=true */
watchOptions: {
poll: true
},
devServer: {
contentBase: BUILD_DIR,
port: DEV_PORT,
historyApiFallback: true,
contentBase: './',
},
resolve: {
extensions: [ '.js', '.jsx' ],
modules: [
'node_modules',
APP_DIR
]
}
};
if (process.env.NODE_ENV === 'production') {
config.plugins.push(
// new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin({ filename: '[name].[chunkhash].css' })
);
config.module.rules.unshift(
{
test: /\.css$|\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use:[
{ loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
},
{ loader: 'sass-loader' }
]
})
}
);
} else {
config.devtool = 'cheap-module-eval-source-map';
config.module.rules.unshift(
{
test: /\.css$|\.scss$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
},
{ loader: 'sass-loader' }
]
}
);
}
module.exports = config;