-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
84 lines (81 loc) · 3 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
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');
let config = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'public'), // ouput path
filename: 'output.js' // output filename
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.scss', '.css', '.jpeg', '.jpg', '.gif', '.png'],
alias: {
images: path.resolve(__dirname, 'src/assets/images')
}
},
module: {
rules: [ // loader 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: [ // webpack plugins
new ExtractTextWebpackPlugin('styles.css'), // call the ExtractTextWebpackPlugin constructor and name our css file
],
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
compress: true, // Enable gzip compression for everything served:
hot: true // Enable webpack's Hot Module Replacement feature
},
devtool: 'eval-source-map', // enable devtool for better debugging experience
}
module.exports = config;
if (process.env.NODE_ENV === 'production') { // if we're in production mode, here's what happens next
module.exports.plugins.push(
new webpack.optimize.UglifyJsPlugin(), // call the uglify plugin
new OptimizeCSSAssets() // call the css optimizer (minfication)
);
}