-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwebpack.config.js
More file actions
135 lines (128 loc) · 3.02 KB
/
webpack.config.js
File metadata and controls
135 lines (128 loc) · 3.02 KB
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
const path = require('path')
const webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')
const packageJson = require('./package.json')
const currentYear = new Date().getFullYear()
const bannerText = `/*!
*
* OverpoweredJS OS v${packageJson.version}
*
* https://github.com/Joe12387/overpoweredjs
*
* Copyright (c) 2022 - ${currentYear} Joe Rutkowski <Joe@dreggle.com>
*
* Released under the OverpoweredJS OS License
*
* This software is subject to very specific licensing terms.
* You should read them before using this software in any capacity.
*
* DO NOT:
* - Remove this banner.
* - Use this software for any commercial purposes.
* - Use this software to track users without their consent.
*
* Please see the LICENSE.md file for more information.
* If you don't have a LICENSE.md file, see the above URL.
*
* Removing this banner is considered a violation of the OverpoweredJS OS License.
*
**/`
class PreserveBannerPlugin {
apply (compiler) {
compiler.hooks.compilation.tap('PreserveBannerPlugin', (compilation) => {
compilation.hooks.processAssets.tap(
{
name: 'PreserveBannerPlugin',
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
},
(assets) => {
for (const assetName in assets) {
if (assetName.endsWith('.js')) {
const source = assets[assetName].source()
assets[assetName] = {
source: () => bannerText + '\n' + source,
size: () => bannerText.length + source.length
}
}
}
}
)
})
}
}
const commonConfig = (isEsm) => ({
entry: './src/opjs.ts',
mode: 'production',
resolve: {
extensions: ['.ts']
},
module: {
rules: [
{
test: /\.ts$/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true,
compilerOptions: isEsm
? {
module: 'es2015'
}
: undefined
}
},
exclude: /node_modules/
}
]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false
}
},
extractComments: false
})
]
},
plugins: []
})
const umdConfig = {
...commonConfig(false),
output: {
path: path.resolve(__dirname, 'dist/es5'),
filename: 'opjs.min.js',
library: {
name: 'opjs',
type: 'umd'
},
globalObject: 'this',
libraryExport: 'default'
},
target: ['web', 'es5'],
plugins: [
...commonConfig(false).plugins,
new PreserveBannerPlugin()
]
}
const esmConfig = {
...commonConfig(true),
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'opjs.esm.js',
library: {
type: 'module'
}
},
experiments: {
outputModule: true
},
plugins: [
...commonConfig(true).plugins,
new PreserveBannerPlugin()
]
}
module.exports = [umdConfig, esmConfig]