forked from edrlab/thorium-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.main.js
133 lines (112 loc) · 4.01 KB
/
webpack.config.main.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
const path = require("path");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const preprocessorDirectives = require("./webpack.config-preprocessor-directives");
// let ignorePlugin = new webpack.IgnorePlugin(new RegExp("/(bindings)/"))
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.
let externals = {
"bindings": "bindings",
"leveldown": "leveldown",
"fsevents": "fsevents",
"conf": "conf",
"pouchdb-adapter-leveldb": "pouchdb-adapter-leveldb",
"electron-devtools-installer": "electron-devtools-installer",
}
if (process.env.NODE_ENV !== "PROD") {
// // 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") {
const nodeExternals = require("./nodeExternals");
externals = [
nodeExternals(
{
processName: "MAIN",
alias: aliases,
// whitelist: ["pouchdb-core"],
}
),
];
// } else {
// const nodeExternals = require("webpack-node-externals");
// // electron-devtools-installer
// externals = [nodeExternals()];
// }
}
console.log("WEBPACK externals (MAIN):");
console.log(JSON.stringify(externals, null, " "));
////// EXTERNALS
////// ================================
let config = Object.assign({}, {
entry: "./src/main.ts",
name: "main",
output: {
filename: "main.js",
path: path.join(__dirname, "dist"),
// https://github.com/webpack/webpack/issues/1114
libraryTarget: "commonjs2",
},
target: "electron-main",
node: {
__dirname: false,
__filename: false,
},
externals: externals,
resolve: {
// Add '.ts' as resolvable extensions.
extensions: [".ts", ".js", ".node"],
alias: aliases,
},
module: {
loaders: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{ test: /\.tsx?$/, loaders: ["awesome-typescript-loader"] },
{ test: /\.node$/, loaders: ["node-loader"] },
],
},
plugins: [
new CopyWebpackPlugin([
{
from: path.join(__dirname, "external-assets"),
to: "external-assets",
}
]),
new CopyWebpackPlugin([
{
from: path.join(__dirname, "node_modules", "r2-navigator-js", "dist", "ReadiumCSS"),
to: "ReadiumCSS",
}
]),
preprocessorDirectives.definePlugin
],
});
if (process.env.NODE_ENV !== "PROD") {
// Bundle absolute resource paths in the source-map,
// so VSCode can match the source file.
config.output.devtoolModuleFilenameTemplate = "[absolute-resource-path]";
config.output.pathinfo = true;
config.devtool = "source-map";
}
module.exports = config;