-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.common.js
103 lines (100 loc) · 3.05 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 HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const TerserJSPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
function staticPage(name) {
return new HtmlWebpackPlugin({
filename: name + '/index.html',
template: 'src/' + name + '.hbs',
chunks: ['main', 'static'],
})
}
module.exports = {
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000
},
entry: {
main: './src/main.js',
tabulasi: './src/tabulasi/tabulasi.ts',
static: './src/static.js',
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin([
{ from: 'src/assets', to: 'assets' },
{ from: 'src/404.html', to: '404.html' },
{ from: 'src/index2.html', to: 'index2.html' },
]),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].[contenthash].css',
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.hbs',
chunks: ['main', 'tabulasi'],
}),
staticPage('disclaimer'),
staticPage('kontak'),
staticPage('faq'),
staticPage('privasi'),
staticPage('jenis-peran-pengunjung'),
staticPage('tentang'),
staticPage('visualisasi'),
],
module: {
rules: [
{
test: /\.hbs$/,
use: [
{
loader: 'handlebars-loader',
options: {
helperDirs: path.join(__dirname, 'src/helpers'),
precompileOptions: {
knownHelpersOnly: false
}
}
}
]
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"sass-loader"
]
},
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
}
],
exclude: /node_modules/,
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
},
};