-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.common.js
103 lines (91 loc) · 2.59 KB
/
webpack.common.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
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { Pages } = require('./webpack.config');
const dist = path.resolve(__dirname, 'dist');
const htmlLoader = path => `!!html-loader?interpolate&attrs=img:data-src!${path}`;
module.exports = {
entry: {
blog_single: './src/blog_single.js',
blog: './src/blog.js',
cart: './src/cart.js',
contact: './src/contact.js',
index: './src/index.js',
product: './src/product.js',
regular: './src/regular.js',
shop: './src/shop.js'
},
output: {
publicPath: '', // prefix path should be '/', for github page please use empty path
path: dist,
filename: 'js/[name].bundle.js' // in directory ./dist/js/
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader, // split css to files, not use style-loader
'css-loader',
/**
* postcss-loader
* Use it after css-loader and style-loader,
* but before other preprocessor loaders
* like e.g sass|less|stylus-loader.
*
* Config file: postcss.config.js
*/
'postcss-loader',
'sass-loader'
]
},
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
attrs: ['img:data-src'],
minimize: false,
removeComments: false,
collapseWhitespace: false,
interpolate: true
}
}
}
]
},
plugins: [
new MiniCssExtractPlugin({
publicPath: '', // prefix path should be '/', for github page please use empty path
path: dist,
filename: 'css/[name].[hash].css', // in directory ./dist/css/
chunkFilename: 'css/[name].[hash].css' // in directory ./dist/css/
}),
new CleanWebpackPlugin([dist]),
new CopyWebpackPlugin([{
from: path.resolve(__dirname, './public'),
to: dist
}]),
...Pages.map(({ template, filename, js }) => new HtmlWebpackPlugin({
template: htmlLoader(template),
filename,
chunks: ['runtime', 'vendors', ...js],
hash: true
}))
],
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
};