-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.common.js
80 lines (73 loc) · 1.93 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
const { merge } = require('webpack-merge');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MiniCssExtractPluginConfig = new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].[contenthash].css',
});
//https://webpack.js.org/plugins/html-webpack-plugin/
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'),
filename: 'index.html',
inject: 'body',
minify: {
collapseWhitespace: true,
minifyCSS: true,
},
});
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CleanupPluginConfig = new CleanWebpackPlugin({});
const CopyPlugin = require('copy-webpack-plugin');
const CopyPluginConfig = new CopyPlugin({
patterns: [{
from: path.join(__dirname, 'assets/i18n'),
to: path.join(__dirname, 'public/assets/i18n'),
}],
});
//merge() isn't required, but it enables autocomplete
module.exports = merge({
entry: path.join(__dirname, 'src', 'main.ts'),
output: {
path: path.join(__dirname, 'public'),
filename: '[name].[contenthash].js',
},
resolve: {
extensions: ['.ts', '.js']
},
plugins: [
CleanupPluginConfig,
HTMLWebpackPluginConfig,
MiniCssExtractPluginConfig,
CopyPluginConfig,
],
module: {
rules: [{
test: /\.ts$/,
loader: 'ts-loader'
}, {
test: /\.css$/,
use: [{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '',
},
}, {
loader: 'css-loader',
options: {
url: true,
import: true,
},
}],
}, {
test: /\.(gltf|mp3|svg|glb|png|jpe?g|eot|ttf|woff|woff2)$/,
use: [{
loader: 'file-loader',
options: {
outputPath: 'assets',
name: '[sha256:hash:base64:16].[ext]',
},
}],
}],
},
});