-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
113 lines (105 loc) · 2.9 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
// Initialization
const webpack = require('webpack');
// File ops
const HtmlWebpackPlugin = require('html-webpack-plugin');
// Folder ops
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
// PostCSS support
const postcssImport = require('postcss-easy-import');
const precss = require('precss');
const autoprefixer = require('autoprefixer');
// Constants
const APP = path.join(__dirname, 'app');
const BUILD = path.join(__dirname, 'build');
const STYLE = path.join(__dirname, 'app/style.css');
const PUBLIC = path.join(__dirname, 'app/public');
const TEMPLATE = path.join(__dirname, 'app/templates/index.html');
const NODE_MODULES = path.join(__dirname, 'node_modules');
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || 8000;
module.exports = {
// Paths and extensions
entry: {
app: APP,
style: STYLE
},
output: {
path: BUILD,
filename: '[name].js',
publicPath: '/'
},
resolve: {
extensions: ['', '.js', '.jsx', '.css']
},
// Loaders for processing different file types
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel?cacheDirectory'],
include: APP
},
{
test: /\.css$/,
loaders: ['style', 'css', 'postcss'],
include: [APP, NODE_MODULES]
},
{
test: /\.json$/,
loader: 'json',
include: [APP, NODE_MODULES]
}
]
},
// Configure PostCSS plugins
postcss: function processPostcss(webpack) { // eslint-disable-line no-shadow
return [
postcssImport({
addDependencyTo: webpack
}),
precss,
autoprefixer({ browsers: ['last 2 versions'] })
];
},
// Source maps used for debugging information
devtool: 'eval-source-map',
// webpack-dev-server configuration
devServer: {
historyApiFallback: true,
hot: true,
progress: true,
stats: 'errors-only',
host: HOST,
port: PORT,
// CopyWebpackPlugin: This is required for webpack-dev-server.
// The path should be an absolute path to your build destination.
outputPath: BUILD
},
// Webpack plugins
plugins: [
// Required to inject NODE_ENV within React app.
// Reduntant package.json script entry does not do that, but required for .babelrc
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development') // eslint-disable-line quote-props
}
}),
new webpack.HotModuleReplacementPlugin(),
new CopyWebpackPlugin([
{ from: PUBLIC, to: BUILD }
],
{
ignore: [
// Doesn't copy Mac storage system files
'.DS_Store'
]
}
),
new HtmlWebpackPlugin({
template: TEMPLATE,
// JS placed at the bottom of the body element
inject: 'body'
})
]
};