forked from SilverHoodCorp/polar-bookshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
137 lines (116 loc) · 4.19 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
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// const workers = require('os').cpus().length - 1;
const workers = 1;
const OUTPUT_PATH = path.resolve(__dirname, 'web/dist');
console.log("Using N workers: " + workers);
console.log("Running in directory: " + __dirname);
console.log("Writing to output path: " + OUTPUT_PATH);
module.exports = {
// mode: 'development',
// stats: 'verbose',
entry: {
// chrome + repository (individually) is about:
//
// 10.2MB raw
// 3.1MB compressed
// (2.4MB with brotli / 22% smaller)
//
// chrome + repository (both) is about
// 5.1MB raw and about
// 1.6MB compressed.
"chrome": [ "./web/js/apps/chrome.ts"],
"pdf": [ "./apps/pdf/src/entry.tsx"],
"repository": [ "./apps/repository/js/entry.tsx"],
"preview": [ "./apps/preview/index.ts"],
"login": [ "./apps/repository/js/login.ts"],
"add-shared-doc": [ "./apps/add-shared-doc/js/index.ts"],
// "all": [ "./web/js/apps/chrome.ts", "./apps/repository/js/entry.tsx", "./apps/repository/js/login.ts"],
// "both": [ "./web/js/apps/chrome.ts", "./apps/repository/js/entry.tsx"],
},
module: {
rules: [
// https://github.com/webpack-contrib/cache-loader
//
// looks like with the cache loader the initial compile is about 10%
// longer but 2x faster once the cache is running.
{ loader: 'cache-loader' },
{
test: path.resolve(__dirname, 'node_modules/electron/index.js'),
use: 'null-loader'
},
{
test: /\.tsx?$/,
// exclude: /node_modules/,
use: [
{
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: 15,
// set this to Infinity in watch mode - see https://github.com/webpack-contrib/thread-loader
poolTimeout: Infinity,
workerParallelJobs: 100,
poolTimeout: 2000,
}
},
{
loader: 'ts-loader',
options: {
// performance: this improved performance by about 2x.
// from 20s to about 10s
transpileOnly: true,
experimentalWatchApi: true,
// IMPORTANT! use happyPackMode mode to speed-up
// compilation and reduce errors reported to webpack
happyPackMode: true
}
}
]
}
]
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ]
},
// only inline-source-map works.
// devtool: "inline-source-map",
output: {
path: OUTPUT_PATH,
filename: '[name]-bundle.js',
// publicPath: '/web/js/apps'
},
node: {
//needed to make webpack work on chrome
fs: 'empty',
net: 'empty',
tls: 'empty',
},
plugins: [
// new BundleAnalyzerPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.$": "jquery",
"window.jQuery": "jquery"
}),
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true })
],
optimization: {
minimize: true,
usedExports: true,
removeAvailableModules: false,
removeEmptyChunks: false,
splitChunks: false,
},
devServer: {
publicPath: 'web/dist',
contentBase: path.join(__dirname, '.'),
compress: true,
port: 443,
watchContentBase: true,
host: 'localapp.getpolarized.io'
}
};