-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
120 lines (119 loc) · 3.7 KB
/
webpack.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
109
110
111
112
113
114
115
116
117
118
119
120
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
// const HtmlWebpackPlugin = require('html-webpack-plugin');
const devMode = process.env.NODE_ENV === 'development';
console.log(`NODE_ENV is: "${process.env.NODE_ENV}", devMode is: "${devMode}"`)
module.exports = {
entry: {
injectmenu: {
import: './frontend/src/index.ts',
// dependOn: 'common'
},
implant: {
import: './frontend/src/implant.ts',
// dependOn: 'common'
},
// common: './frontend/src/common/index.ts',
coll: {
import: './frontend/sass/public/coll.sass'
}
},
devServer: {
static: {
directory: path.resolve(__dirname, './demo/'),
}
},
devtool: devMode ? 'inline-source-map' : 'source-map',
module: {
rules: [
{ // pictures
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{ // fonts
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
{ // typescript
test: /\.ts$/i,
use: 'ts-loader',
// exclude: /node_modules/,
},
{ // (plain) css. loader pipeline is traversed bottom-to-top (css -> style/extract)
test: /\.css$/i,
use: [
// fallback to style-loader in development
devMode
? "style-loader"
: MiniCssExtractPlugin.loader,
"css-loader",
],
},
{ // sass. loader pipeline is traversed bottom-to-top (sass -> css -> style/extract)
test: /\.s[ac]ss$/i,
use: [
// fallback to style-loader in development
devMode
? "style-loader"
: MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "sass-loader",
options: {
implementation: require("sass"),
sassOptions: {
fiber: false,
},
},
},
],
},
],
},
plugins: [].concat(devMode ? [
// new HtmlWebpackPlugin()
] : [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
// filename: "public/[name].css",
// chunkFilename: "public/[id].css",
filename: (pathData) => pathData.chunk.name === 'coll' ? 'public/[name].css' : 'loggedin/[name].css',
chunkFilename: (pathData) => pathData.chunk.name === 'coll' ? 'public/[id].css' : 'loggedin/[id].css',
}),
new CopyPlugin({
patterns: [
// { from: path.posix.join(path.resolve(__dirname, '../frontend/html/'), '**/*.htm'), to: path.resolve(__dirname,'../dist/') },
{ from: '**/*.htm', to: path.resolve(__dirname, './dist/'), context: './frontend/html/' },
],
}),
]),
resolve: {
extensions: ['.ts', '.js'],
},
output: {
filename: (pathData) => pathData.chunk.name === 'coll' ? 'public/[name].js' : 'loggedin/[name].js',
assetModuleFilename: "public/[name][ext]",
hashFunction: "xxhash64",
path: devMode ? path.resolve(__dirname, './demo/') : path.resolve(__dirname, './dist/'),
clean: !devMode
},
optimization: {
runtimeChunk: false, // 'single' would shave off 7kb, but I prefer injecting only one script file
moduleIds: 'deterministic',
// splitChunks: {
// cacheGroups: {
// mmenu: {
// test: /[\\/]node_modules[\\/]mmenu-js[\\/]/,
// name: 'mmenu',
// chunks: 'all',
// },
// },
// chunks: 'all',
// },
},
experiments: {
futureDefaults: true,
}
};