-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathwebpack.config.js
86 lines (85 loc) · 2.41 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
const path = require("path");
/** @type {import("webpack")} */
const webpack = module.parent.require("webpack");
const CopyPlugin = require("copy-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin").CleanWebpackPlugin;
const dev = false;
/** @type {import("webpack").Configuration} */
const options = {
entry: { index: "./dist/server.js" },
target: "node",
mode: dev ? "none" : "production",
devtool: dev ? 'source-map' : "",
watch: false,
plugins: [
new webpack.DefinePlugin({
GENTLY: false,
global: { GENTLY: false },
"typeof __non_webpack_require__": JSON.stringify("function")
}),
new webpack.BannerPlugin({
banner: "#!/usr/bin/env node", raw: true
}),
new CopyPlugin([
{ from: 'src/client', to: './client/' },
{ from: 'src/datafolder', to: './datafolder/' },
{ from: 'preflighter.js', to: '.' },
{ from: 'scripts', to: './scripts/' },
{ from: 'README.md', to: '.' },
]),
new CleanWebpackPlugin({
cleanAfterEveryBuildPatterns: [
"rootpath.d.ts",
"rootpath.js",
"server.d.ts",
"server.js",
"package.d.ts",
"server/"
],
cleanOnceBeforeBuildPatterns: []
}),
{
apply: (compiler) => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
// make the package.json file for the npm package
const json = JSON.parse(require("fs").readFileSync("./package.json", "utf8"));
// remove keys not used in the production build
delete json.devDependencies;
delete json.main;
delete json.scripts;
// set the webpack output as the bin file
json.bin = "./index.js";
// save to the output directory
require("fs").writeFileSync("./dist/package.json", JSON.stringify(json, null, 2), "utf8");
});
}
}
],
node: {
global: true,
__dirname: false,
__filename: false
},
resolve: {
alias: {
"../package.json": path.resolve(__dirname, "package.json")
}
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, "dist"),
libraryTarget: 'commonjs2'
},
externals: [
"bufferutil",
"utf-8-validate",
"tiddlywiki-production",
"tiddlywiki-production-server",
"tiddlywiki-production-client"
],
stats: {
all: true
},
};
module.exports = options;
// export default options;