-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
100 lines (97 loc) · 3.11 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
const webpack = require("webpack");
const path = require("path");
const ExtractTextWebpackPlugin = require("extract-text-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const OptimizeCSSAssets = require("optimize-css-assets-webpack-plugin");
const DashboardPlugin = require("webpack-dashboard/plugin");
const config = {
entry: "./src/index.js", // entry file
output: {
path: path.resolve(__dirname, "./public"), // ouput path
filename: "output.js" // output filename
},
resolve: {
// These options change how modules are resolved
extensions: [
".js",
".jsx",
".json",
".scss",
".css",
".jpeg",
".jpg",
".gif",
".png"
], // Automatically resolve certain extensions
alias: {
// Create aliases
images: path.resolve(__dirname, "src/assets/images") // src/assets/images alias
}
},
module: {
rules: [
{
test: /\.js$/, // files ending with .js
exclude: /node_modules/, // exclude the node_modules directory
loader: "babel-loader" // use this (babel-core) loader
},
{
test: /\.scss$/, // files ending with .scss
use: ['css-hot-loader'].concat(ExtractTextWebpackPlugin.extract({ // HMR for styles
fallback: 'style-loader',
use: ['css-loader', 'sass-loader', 'postcss-loader'],
})),
},
{
test: /\.jsx$/, // all files ending with .jsx
loader: "babel-loader", // use the babel-loader for all .jsx files
exclude: /node_modules/ // exclude searching for files in the node_modules directory
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
"file-loader?context=src/assets/images/&name=images/[path][name].[ext]",
{
// images loader
loader: "image-webpack-loader",
query: {
mozjpeg: {
progressive: true
},
gifsicle: {
interlaced: false
},
optipng: {
optimizationLevel: 4
},
pngquant: {
quality: "75-90",
speed: 3
}
}
}
],
exclude: /node_modules/,
include: __dirname
}
] // end rules
},
plugins: [
new ExtractTextWebpackPlugin("styles.css"), // call the ExtractTextWebpackPlugin constructor and name our css file
new DashboardPlugin()
],
devServer: {
contentBase: path.resolve(__dirname, "./public"), // A directory or URL to serve HTML content from.
historyApiFallback: true, // fallback to /index.html for Single Page Applications.
inline: true, // inline mode (set to false to disable including client scripts (like livereload)
open: true // open default browser while launching
},
devtool: "eval-source-map" // enable devtool for better debugging experience
};
module.exports = config;
if (process.env.NODE_ENV === "production") {
module.exports.plugins.push(
new webpack.optimize.UglifyJsPlugin(), // call the uglify plugin
new OptimizeCSSAssets()
);
}