meocord 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -3
- package/webpack.config.js +98 -65
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meocord",
|
|
3
3
|
"description": "MeoCord is a lightweight and modular framework for building scalable Discord bots using TypeScript and Discord.js. It simplifies bot development with an extensible architecture, TypeScript-first approach, and powerful CLI tools.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"packageManager": "yarn@4.7.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
@@ -94,11 +94,9 @@
|
|
|
94
94
|
"dayjs": "^1.11.13",
|
|
95
95
|
"discord.js": "^14.18.0",
|
|
96
96
|
"dotenv": "^16.4.7",
|
|
97
|
-
"file-loader": "^6.2.0",
|
|
98
97
|
"inversify": "^7.1.0",
|
|
99
98
|
"lodash-es": "^4.17.21",
|
|
100
99
|
"nodemon": "^3.1.9",
|
|
101
|
-
"raw-loader": "^4.0.2",
|
|
102
100
|
"reflect-metadata": "^0.2.2",
|
|
103
101
|
"simple-git": "^3.27.0",
|
|
104
102
|
"terser-webpack-plugin": "^5.3.14",
|
package/webpack.config.js
CHANGED
|
@@ -23,83 +23,116 @@ import TerserPlugin from 'terser-webpack-plugin'
|
|
|
23
23
|
import { loadMeoCordConfig } from './dist/util/meocord-config-loader.util.js'
|
|
24
24
|
import { prepareModifiedTsConfig } from './dist/util/tsconfig.util.js'
|
|
25
25
|
|
|
26
|
+
const CWD = process.cwd()
|
|
27
|
+
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
|
|
28
|
+
const SRC_DIR = path.resolve(CWD, 'src')
|
|
29
|
+
const DIST_DIR = path.resolve(CWD, 'dist')
|
|
30
|
+
|
|
26
31
|
const meocordConfig = loadMeoCordConfig()
|
|
27
32
|
const tsConfigPath = prepareModifiedTsConfig()
|
|
28
33
|
|
|
29
34
|
const baseRules = [
|
|
30
35
|
{
|
|
31
36
|
test: /\.ts$/,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
+
loader: 'ts-loader',
|
|
38
|
+
options: {
|
|
39
|
+
configFile: tsConfigPath,
|
|
40
|
+
transpileOnly: true,
|
|
37
41
|
},
|
|
38
42
|
exclude: /node_modules/,
|
|
39
43
|
},
|
|
40
|
-
{
|
|
41
|
-
test: /\.(gif|jpg|jpeg|png|svg|woff|woff2|eot|ttf|otf)$/i,
|
|
42
|
-
type: 'javascript/auto',
|
|
43
|
-
exclude: /node_modules/,
|
|
44
|
-
use: {
|
|
45
|
-
loader: 'file-loader',
|
|
46
|
-
options: { name: '[path][name].[ext]', context: path.resolve(process.cwd(), 'src') },
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
test: /\.html$/i,
|
|
51
|
-
use: 'raw-loader',
|
|
52
|
-
},
|
|
53
44
|
]
|
|
54
45
|
|
|
55
46
|
/**
|
|
56
|
-
*
|
|
57
|
-
* Uses `tsconfig` for resolving paths and applies custom `meocord` configuration if available.
|
|
58
|
-
*
|
|
59
|
-
* @param {import('webpack').Configuration} [config={}] Custom overrides for the base configuration.
|
|
60
|
-
* @returns {import('webpack').Configuration} The Webpack configuration object.
|
|
47
|
+
* Merges two arrays returning unique elements
|
|
61
48
|
*/
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
externals: Array.from(new Set([NodeExternals({ importType: 'module' }), ...(config?.externals || [])])),
|
|
78
|
-
module: {
|
|
79
|
-
...config?.module,
|
|
80
|
-
rules: Array.from(new Set([...baseRules, ...(config?.module?.rules || [])])),
|
|
81
|
-
},
|
|
82
|
-
resolve: {
|
|
83
|
-
...config?.resolve,
|
|
84
|
-
plugins: Array.from(
|
|
85
|
-
new Set([new TsconfigPathsPlugin({ configFile: tsConfigPath }), ...(config?.resolve?.plugins || [])]),
|
|
86
|
-
),
|
|
87
|
-
extensions: Array.from(new Set(['.ts', '.js', ...(config?.resolve?.extensions || [])])),
|
|
88
|
-
},
|
|
89
|
-
output: {
|
|
90
|
-
...config?.output,
|
|
91
|
-
filename: 'main.js',
|
|
92
|
-
path: path.resolve(process.cwd(), 'dist'),
|
|
93
|
-
publicPath: 'dist/',
|
|
94
|
-
library: {
|
|
95
|
-
type: 'module',
|
|
49
|
+
const mergeUnique = (base = [], additions = []) => Array.from(new Set([...base, ...additions]))
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates webpack configuration with framework defaults
|
|
53
|
+
*/
|
|
54
|
+
const createWebpackConfig = (overrides = {}) => {
|
|
55
|
+
const baseConfig = {
|
|
56
|
+
mode: overrides.mode ?? (IS_PRODUCTION ? 'production' : 'development'),
|
|
57
|
+
entry: overrides.entry ?? path.resolve(SRC_DIR, 'main.ts'),
|
|
58
|
+
target: 'node',
|
|
59
|
+
externals: mergeUnique([NodeExternals({ importType: 'module' })], overrides.externals),
|
|
60
|
+
module: {
|
|
61
|
+
...overrides.module,
|
|
62
|
+
rules: mergeUnique(baseRules, overrides.module?.rules),
|
|
96
63
|
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
64
|
+
resolve: {
|
|
65
|
+
...overrides.resolve,
|
|
66
|
+
extensions: mergeUnique(['.ts', '.js'], overrides.resolve?.extensions),
|
|
67
|
+
plugins: mergeUnique([new TsconfigPathsPlugin({ configFile: tsConfigPath })], overrides.resolve?.plugins),
|
|
68
|
+
},
|
|
69
|
+
output: {
|
|
70
|
+
filename: 'main.js',
|
|
71
|
+
path: DIST_DIR,
|
|
72
|
+
publicPath: path.join(process.cwd(), 'dist/'),
|
|
73
|
+
library: { type: 'module' },
|
|
74
|
+
clean: IS_PRODUCTION,
|
|
75
|
+
...overrides.output,
|
|
76
|
+
},
|
|
77
|
+
experiments: {
|
|
78
|
+
outputModule: true,
|
|
79
|
+
...overrides.experiments,
|
|
80
|
+
},
|
|
81
|
+
stats: overrides.stats ?? (IS_PRODUCTION ? 'normal' : 'errors-warnings'),
|
|
82
|
+
devtool: overrides.devtool ?? (IS_PRODUCTION ? 'source-map' : 'eval-source-map'),
|
|
83
|
+
performance: {
|
|
84
|
+
hints: overrides.performance?.hints ?? (IS_PRODUCTION ? 'warning' : false),
|
|
85
|
+
...overrides.performance,
|
|
86
|
+
},
|
|
87
|
+
...overrides,
|
|
88
|
+
optimization: {
|
|
89
|
+
...overrides.optimization,
|
|
90
|
+
minimize: overrides.optimization?.minimize ?? IS_PRODUCTION,
|
|
91
|
+
minimizer: [],
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const finalMinimizerArray = []
|
|
96
|
+
const shouldMinimize = baseConfig.optimization.minimize
|
|
97
|
+
|
|
98
|
+
if (shouldMinimize) {
|
|
99
|
+
const userProvidedMinimizers = overrides.optimization?.minimizer
|
|
100
|
+
let lastTerserInstance = null
|
|
101
|
+
const otherMinimizers = []
|
|
102
|
+
|
|
103
|
+
if (Array.isArray(userProvidedMinimizers)) {
|
|
104
|
+
for (let i = userProvidedMinimizers.length - 1; i >= 0; i--) {
|
|
105
|
+
const minimizer = userProvidedMinimizers[i]
|
|
106
|
+
if (minimizer?.constructor?.name === 'TerserPlugin') {
|
|
107
|
+
if (!lastTerserInstance) {
|
|
108
|
+
lastTerserInstance = minimizer
|
|
109
|
+
}
|
|
110
|
+
} else if (minimizer) {
|
|
111
|
+
otherMinimizers.unshift(minimizer)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
finalMinimizerArray.push(...otherMinimizers)
|
|
117
|
+
|
|
118
|
+
const terserPluginToUse = lastTerserInstance
|
|
119
|
+
? new TerserPlugin({
|
|
120
|
+
...lastTerserInstance.options,
|
|
121
|
+
terserOptions: {
|
|
122
|
+
...lastTerserInstance.options?.terserOptions,
|
|
123
|
+
keep_classnames: true,
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
: new TerserPlugin({ terserOptions: { keep_classnames: true } })
|
|
127
|
+
|
|
128
|
+
finalMinimizerArray.push(terserPluginToUse)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
baseConfig.optimization.minimizer = finalMinimizerArray
|
|
132
|
+
|
|
133
|
+
return baseConfig
|
|
134
|
+
}
|
|
103
135
|
|
|
104
|
-
const
|
|
105
|
-
|
|
136
|
+
const initialConfig = createWebpackConfig()
|
|
137
|
+
const userModifiedConfig = meocordConfig?.webpack?.(initialConfig)
|
|
138
|
+
export default createWebpackConfig(userModifiedConfig ?? {})
|