-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
146 lines (138 loc) · 3.69 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
138
139
140
141
142
143
144
145
146
const webpack = require("webpack");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlWebpackHarddiskPlugin = require("html-webpack-harddisk-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const Handlebars = require("handlebars");
const packageJSON = require("./package.json");
const blueprintJSON = require("./src/readme/blueprint.json");
const fs = require("fs");
const { marked } = require("marked");
const JSONInfo = Object.assign(
{
pkg: packageJSON,
},
blueprintJSON
);
const processMD = (file) => {
return Handlebars.compile(marked.parse(fs.readFileSync(file).toString()))(JSONInfo);
};
const baseConfig = {
entry: "./src/browser/index.ts",
devtool: "source-map",
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-typescript"],
},
},
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
};
const public = Object.assign({}, baseConfig, {
output: {
filename: `${packageJSON.details.stylizedName}.js`,
path: path.resolve(__dirname, "public"),
clean: false,
globalObject: "this",
library: {
name: `${packageJSON.details.stylizedName}`,
type: "umd",
},
},
plugins: [
new webpack.BannerPlugin({
banner: `${packageJSON.details.stylizedName}.js v${packageJSON.version}\n${packageJSON.homepage}\nBuilt: ${new Date().toLocaleDateString("en-us", {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
timeZoneName: "short",
})}`,
entryOnly: true,
}),
new HtmlWebpackPlugin({
title: `${packageJSON.details.stylizedName}.js`,
template: "src/demo/index.html",
filename: "../public/index.html",
templateParameters: {
description: packageJSON.description,
subtitle: packageJSON.details.subtitle,
installationUsage: processMD("./src/readme/installation-usage.md"),
intro: processMD("./src/readme/intro.md"),
repo: packageJSON.repository.url.substring(0, packageJSON.repository.url.length - 4),
homepage: packageJSON.homepage,
},
alwaysWriteToDisk: true,
scriptLoading: "blocking",
inject: "head",
}),
new HtmlWebpackHarddiskPlugin(),
new CopyPlugin({
patterns: [
{ from: "src/demo/style.css", to: "style.css" },
{ from: "src/demo/brandojs-screencap-social-share.gif", to: "brandojs-screencap-social-share.gif" },
{ from: "src/demo/img", to: "img" },
{ from: "brandojs-demo-cap.webp", to: "brandojs-demo-cap.webp" },
],
}),
],
devServer: {
static: path.join(__dirname, "public"),
compress: true,
open: true,
hot: true,
port: 4000,
historyApiFallback: true,
},
});
const dist = Object.assign({}, baseConfig, {
output: {
filename: `${packageJSON.details.stylizedName}.js`,
path: path.resolve(__dirname, "dist"),
clean: true,
globalObject: "this",
library: {
name: `${packageJSON.details.stylizedName}`,
type: "umd",
},
},
plugins: [
new webpack.BannerPlugin({
banner: `${packageJSON.details.stylizedName}.js v${packageJSON.version}\n${packageJSON.homepage}\nBuilt: ${new Date().toLocaleDateString("en-us", {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
timeZoneName: "short",
})}`,
entryOnly: true,
}),
new CopyPlugin({
patterns: [{ from: "src/demo/img", to: "img" }],
}),
],
});
module.exports = [public, dist];