-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
64 lines (59 loc) · 1.7 KB
/
webpack.config.js
File metadata and controls
64 lines (59 loc) · 1.7 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
const path = require("path");
const pkg = require("./package.json");
// Plugins
const TSConfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { DefinePlugin, BannerPlugin } = require("webpack");
// Variables
const sourcePath = path.join(__dirname, "./src/");
const outPath = path.join(__dirname, `./dist/`);
module.exports = (env, argv) => {
const isProduction = argv.mode === "production";
const buildDate = new Date();
const libraryName = pkg.name;
const libraryBanner = `${pkg.name}\n${pkg.description}\n
@version v${pkg.version} - ${buildDate.toISOString()}
@author ${pkg.author}
@repository ${pkg.repository.url}
@license ${pkg.license}`;
return {
context: sourcePath,
entry: ["main.ts"],
output: {
publicPath: "/",
library: libraryName,
libraryTarget: "umd",
path: outPath,
filename: "[name].js",
chunkFilename: isProduction
? "chunks/[name].[contenthash].js"
: "chunks/[name].[hash].js",
},
target: "node",
resolve: {
extensions: [".js", ".ts"],
plugins: [new TSConfigPathsPlugin()],
mainFields: ["module", "browser", "main"],
},
module: {
rules: [
{
test: /\.ts$/,
use: ["ts-loader"],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new DefinePlugin({
__LIB_VERSION__: JSON.stringify({
build: pkg.version,
date: buildDate.toISOString(),
stamp: Math.floor(buildDate.getTime() / 1000),
}),
}),
new BannerPlugin(libraryBanner),
],
devtool: isProduction ? "hidden-source-map" : "eval-source-map",
};
};