forked from edrlab/thorium-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.renderer-pdf.js
210 lines (188 loc) · 6.5 KB
/
webpack.config.renderer-pdf.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const TerserPlugin = require("terser-webpack-plugin");
const path = require("path");
const webpack = require("webpack");
const preprocessorDirectives = require("./webpack.config-preprocessor-directives");
const aliases = {
"readium-desktop": path.resolve(__dirname, "src"),
"@r2-utils-js": "r2-utils-js/dist/es6-es2015/src",
"@r2-lcp-js": "r2-lcp-js/dist/es6-es2015/src",
"@r2-opds-js": "r2-opds-js/dist/es6-es2015/src",
"@r2-shared-js": "r2-shared-js/dist/es6-es2015/src",
"@r2-streamer-js": "r2-streamer-js/dist/es6-es2015/src",
"@r2-navigator-js": "r2-navigator-js/dist/es6-es2015/src",
};
////// ================================
////// EXTERNALS
// Some modules cannot be bundled by Webpack
// for example those that make internal use of NodeJS require() in special ways
// in order to resolve asset paths, etc.
// In DEBUG / DEV mode, we just external-ize as much as possible (any non-TypeScript / non-local code),
// to minimize bundle size / bundler computations / compile times.
// const nodeExternals = require("webpack-node-externals");
const nodeExternals = require("./nodeExternals");
// Get node environment
const nodeEnv = process.env.NODE_ENV || "development";
console.log(`PDF nodeEnv: ${nodeEnv}`);
// https://github.com/edrlab/thorium-reader/issues/1097#issuecomment-643406149
const useLegacyTypeScriptLoader = process.env.USE_LEGACY_TYPESCRIPT_LOADER
? true
: false;
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
ForkTsCheckerWebpackPlugin.prototype[require("util").inspect.custom] = (_depth, _options) => { return "ForkTsCheckerWebpackPlugin" };
const checkTypeScriptSkip =
nodeEnv !== "production" ?
(process.env.SKIP_CHECK_TYPESCRIPT === "1" ? true : false)
: false
;
let externals = {
bindings: "bindings",
leveldown: "leveldown",
fsevents: "fsevents",
conf: "conf",
sqlite3: "sqlite3",
};
if (nodeEnv !== "production") {
// // externals = Object.assign(externals, {
// // "electron-config": "electron-config",
// // }
// // );
// const { dependencies } = require("./package.json");
// const depsKeysArray = Object.keys(dependencies || {});
// const depsKeysObj = {};
// depsKeysArray.forEach((depsKey) => { depsKeysObj[depsKey] = depsKey });
// externals = Object.assign(externals, depsKeysObj);
// delete externals["pouchdb-core"];
if (process.env.WEBPACK === "bundle-external") {
externals = [
nodeExternals({
processName: "PDF",
alias: aliases,
// whitelist: ["pouchdb-core"],
}),
];
} else {
externals.devtron = "devtron";
}
}
console.log("WEBPACK externals (PDF):");
console.log(JSON.stringify(externals, null, " "));
////// EXTERNALS
////// ================================
let config = Object.assign(
{},
{
entry: "./src/renderer/reader/pdf/webview/index_pdf.ts",
name: "renderer pdf webview index",
output: {
filename: "index_pdf.js",
path: path.join(__dirname, "dist"),
// https://github.com/webpack/webpack/issues/1114
libraryTarget: "commonjs2",
},
target: "electron-renderer",
mode: "production", // nodeEnv,
externals: externals,
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
alias: aliases,
},
stats: {
// warningsFilter: /export .* was not found in/,
},
module: {
rules: [
{
test: /\.(jsx?|tsx?)$/,
use: [
{
loader: path.resolve(
"./scripts/webpack-loader-scope-checker.js"
),
options: {
forbid: "library",
},
},
],
},
{
test: /\.tsx$/,
loader: useLegacyTypeScriptLoader
? "awesome-typescript-loader"
: "ts-loader",
options: {
transpileOnly: true, // checkTypeScriptSkip
},
},
{
test: /\.ts$/,
use: [
{
loader: "babel-loader",
options: {
presets: [],
plugins: ["macros"],
},
},
{
loader: useLegacyTypeScriptLoader
? "awesome-typescript-loader"
: "ts-loader",
options: {
transpileOnly: true, // checkTypeScriptSkip
},
},
],
},
],
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: "disabled",
defaultSizes: "stat", // "parsed"
openAnalyzer: false,
generateStatsFile: true,
statsFilename: "stats_renderer-pdf.json",
statsOptions: null,
excludeAssets: null,
}),
preprocessorDirectives.definePlugin,
],
}
);
if (!checkTypeScriptSkip) {
config.plugins.push(new ForkTsCheckerWebpackPlugin({
// measureCompilationTime: true,
}));
}
if (nodeEnv !== "production") {
} else {
config.optimization =
{
...(config.optimization || {}),
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
exclude: /MathJax/,
terserOptions: {
compress: false,
mangle: false,
output: {
comments: false,
},
},
}),
],
};
// {
// minimize: false,
// };
config.plugins.push(
new webpack.IgnorePlugin({ resourceRegExp: /^devtron$/ })
);
config.plugins.push(
new webpack.IgnorePlugin({ resourceRegExp: /^react-axe$/ })
);
}
module.exports = config;