-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.build.config.js
108 lines (100 loc) · 2.41 KB
/
webpack.build.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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const extractSass = new ExtractTextPlugin({
filename: '[name].[hash].css',
disable: process.env.NODE_ENV === 'development',
});
module.exports = {
// context: path.resolve(__dirname, 'src'),
entry: {
app: ['./index.js'],
},
cache: false,
devtool: 'source-map',
output: {
path: path.resolve(__dirname, 'docs'),
filename: '[name].[hash].js',
},
resolve: {
extensions: ['.js'],
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test:/\.(s*)css$/,
use: extractSass.extract({
use: [
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
fallback: [
{
loader: 'style-loader',
},
],
}),
},
{
test: /\.(jpe?g|png|gif|svg)$/,
loader: 'url-loader',
options: {
limit: 8000, // Convert images < 8kb to base64 strings
name: 'images/[hash]-[name].[ext]'
}
},
{
test: /\.html$/,
loader: 'html-loader',
options: {
// otherwise inline SVG fails with a parse error!
minimize: false
}
},
],
},
plugins: [
// this seems to take forever!! but needed for tree-shaking
new UglifyJSPlugin({
uglifyOptions: {
compress: {
warnings: false,
},
output: {
comments: false
}
},
sourceMap: true
}),
extractSass,
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0,
}),
new ExtractTextPlugin('app.[hash].css'),
new HtmlWebpackPlugin({
template: './index.html'
}),
new CopyWebpackPlugin([
{ from: 'images/', to: 'images/' },
{ from: 'libs/', to: 'libs/' },
{ from: 'data/', to: 'data/' },
])
],
};