-
Notifications
You must be signed in to change notification settings - Fork 97
/
webpack.config.js
137 lines (130 loc) · 3.41 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { fileURLToPath } from 'url'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as process from 'process'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import developmentOptions from './fvtt.config.js'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import TerserPlugin from 'terser-webpack-plugin'
import WebpackBar from 'webpackbar'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
/** Set the run mode for @constant bundleScript */
const buildMode =
process.argv[3] === 'production' ? 'production' : 'development'
function systemFolderName () {
if (buildMode === 'development') {
const validDirectoryName = /^[a-zA-Z].*/
if (validDirectoryName.test(developmentOptions.systemFolderName)) {
return developmentOptions.systemFolderName
}
}
return 'CoC7'
}
/**
* Get the user data path for Foundry VTT, based on what is configured on key
* userDataPath inside fvtt.config.js
*/
function buildDestination () {
const { userDataPath } = developmentOptions
if (fs.existsSync(userDataPath)) {
return path.join(userDataPath, 'Data', 'systems', systemFolderName())
}
return path.join(__dirname, 'build/')
}
/** Set optimization options for when @constant buildMode is `production` */
const optimization =
buildMode === 'production'
? {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: false
}
}),
new CssMinimizerPlugin()
],
splitChunks: {
chunks: 'all',
cacheGroups: {
default: {
name: 'main',
test: 'module/coc7.js'
}
}
}
}
: undefined
/**
* The nerve center. Here are all the settings for compiling bundles:
* production and development
*/
const bundleScript = {
bail: buildMode === 'production',
context: __dirname,
entry: './module/coc7.js',
devtool: 'inline-source-map',
mode: buildMode,
module: {
rules: [
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
sourceMap: true
}
},
{
loader: 'less-loader',
options: { sourceMap: true }
}
]
},
{
loader: 'thread-loader',
options: {
workers: os.cpus().length + 1,
poolRespawn: false,
poolTimeout: buildMode === 'production' ? 500 : Infinity
}
}
]
},
optimization,
output: {
clean: (buildMode === 'production'),
path: buildDestination(),
filename: 'bundle.js'
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: 'assets/', to: 'assets/' },
{ from: 'lang/', to: 'lang/' },
{ from: 'lib/', to: 'lib/' },
{ from: 'LICENSE' },
{ from: 'packs/', to: 'packs/' },
{ from: 'README.md' },
{ from: 'system.json' },
{ from: 'template.json' },
{ from: 'templates/', to: 'templates/' }
]
}),
new MiniCssExtractPlugin({
filename: 'coc7g.css',
insert: 'head'
}),
new WebpackBar({})
],
resolve: {
extensions: ['.js']
},
watch: buildMode === 'development'
}
export default bundleScript