-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.prod.ts
61 lines (60 loc) · 1.63 KB
/
webpack.prod.ts
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
import webpack from 'webpack'
import common from './webpack.common'
import path from 'path'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import TerserPlugin from 'terser-webpack-plugin'
import OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import merge from 'webpack-merge'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
//
const config: webpack.Configuration = merge(common, {
mode: 'production',
output: {
filename: '[name].[contentHash].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist',
},
optimization: {
minimizer: [new OptimizeCssAssetsPlugin(), new TerserPlugin()],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[contentHash].css',
}),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/template.html',
minify: {
removeAttributeQuotes: true,
collapseWhitespace: true,
removeComments: true,
},
}),
],
module: {
rules: [
{
test: /\.scss$/,
use: [
// Order of the loaders are important!
MiniCssExtractPlugin.loader, // 3. Extract CSS into files
'css-loader', // 2. Turns CSS into commonjs
'sass-loader', // 1. Turns SCSS into CSS
],
},
{
test: /\.(svg|png|jpe?g|gif)$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: '/img',
publicPath: '/img',
},
},
},
],
},
})
export default config