This repository was archived by the owner on Mar 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
88 lines (76 loc) · 1.82 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
import webpack from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';
import * as path from 'path';
import {fileURLToPath} from 'url';
import info from './src/info.js';
/**
* @param {string} format format name
* @returns {string}
*/
const getBanner = () => {
return `HashJs v${info.version}
Copyright (c) ${new Date().getFullYear()} Irmmr
MIT License
https://github.com/irmmr/hash.js`;
}
const modulename = info.module;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const banner = new webpack.BannerPlugin({
banner: getBanner()
});
const config = {
entry: path.resolve(__dirname, "src/hash.js"),
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
extractComments: false
})]
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: "babel-loader",
},
],
},
plugins: [banner]
}
export default function buildData(env) {
// is dev mode?
const dev = env['development'] ?? false;
// is test mode?
const test = env['test'] ?? false;
// build lab for better test!
if (test) {
return Object.assign({}, config, {
output: {
path: path.resolve(__dirname, "lab"),
filename: "hash.js",
library: modulename,
libraryTarget: "umd",
libraryExport: "default"
},
mode: "development"
});
}
const outputs = [
{
output: {
path: path.resolve(__dirname, "dist"),
filename: dev ? 'hash.js' : 'hash.min.js',
library: modulename,
libraryTarget: "umd",
libraryExport: "default"
}
}
]
const mode = dev ? 'development' : 'production';
let fetch = [];
outputs.forEach(d => {
fetch.push( Object.assign({}, config, d, { mode }) );
});
return fetch;
}