This repository was archived by the owner on May 19, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
170 lines (165 loc) · 4.3 KB
/
Copy pathwebpack.config.js
File metadata and controls
170 lines (165 loc) · 4.3 KB
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
var path = require('path');
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
var StringReplacePlugin = require("string-replace-webpack-plugin");
var webpack = require('webpack');
var pkg = require('./package.json');
var banner = '/*! ' + pkg.name + ' v' + pkg.version + ', @license ' + pkg.license + ', @link ' + pkg.homepage + ' */';
module.exports = {
mode: 'production',
entry: {
'pdfmake': './src/browser-extensions/pdfMake.js',
'pdfmake.min': './src/browser-extensions/pdfMake.js'
},
output: {
path: path.join(__dirname, './build'),
filename: '[name].js',
libraryTarget: 'umd',
// Workaround https://github.com/webpack/webpack/issues/6642 until https://github.com/webpack/webpack/issues/6525 lands.
globalObject: `typeof self !== 'undefined' ? self : this`
},
resolve: {
alias: {
fs: path.join(__dirname, './src/browser-extensions/virtual-fs.js')
}
},
node: {
// Prevent webpack from injecting setImmediate polyfill, which includes a "new Function" through a global polyfill - which cannot be used in a CSP environment with sane defaults
setImmediate: false
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
"@babel/preset-env",
{
targets: {
"ie": "11"
},
modules: false,
useBuiltIns: 'usage',
loose: true
}
]
]
}
}
},
// for fs don't use babel _interopDefault command
{
enforce: 'pre',
test: /pdfkit[/\\]js[/\\]/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: "import fs from 'fs';",
replacement: function () {
return "var fs = require('fs');";
}
}
]
})
},
{
test: /\.js$/,
include: /(pdfkit|saslprep)/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
"@babel/preset-env",
{
targets: {
"ie": "11"
},
modules: false,
useBuiltIns: 'usage',
loose: true
}
]
],
plugins: ["@babel/plugin-transform-modules-commonjs"]
}
}
},
{ test: /pdfMake.js$/, loader: 'expose-loader?pdfMake', include: [path.join(__dirname, './src/browser-extensions')] },
/* Can be removed after new pdfkit release */
/* waiting to release included PR https://github.com/foliojs/pdfkit/pull/934 */
{
test: /pdfkit[/\\]js[/\\]/, loader: StringReplacePlugin.replace({
replacements: [
{
pattern: 'return this.font(\'Helvetica\');',
replacement: function () {
return '';
}
}
]
})
},
{
test: /fontkit[/\\]index.js$/, loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /fs\./g,
replacement: function () {
return 'require(\'fs\').';
}
}
]
})
},
/* temporary bugfix for FileSaver: added hack for mobile device support, see https://github.com/bpampuch/pdfmake/issues/1664 */
/* waiting to merge and release PR https://github.com/eligrey/FileSaver.js/pull/533 */
{
test: /FileSaver.min.js$/, loader: StringReplacePlugin.replace({
replacements: [
{
pattern: '"download"in HTMLAnchorElement.prototype',
replacement: function () {
return '(typeof HTMLAnchorElement !== "undefined" && "download" in HTMLAnchorElement.prototype)';
}
}
]
})
},
{ enforce: 'post', test: /fontkit[/\\]index.js$/, loader: "transform-loader?brfs" },
{ enforce: 'post', test: /unicode-properties[/\\]index.js$/, loader: "transform-loader?brfs" },
{ enforce: 'post', test: /linebreak[/\\]src[/\\]linebreaker.js/, loader: "transform-loader?brfs" }
]
},
optimization: {
minimizer: [
new UglifyJsPlugin({
include: /\.min\.js$/,
sourceMap: true,
uglifyOptions: {
output: {
comments: /^! pdfmake/
},
compress: {
drop_console: true
},
mangle: {
reserved: ['HeadTable', 'NameTable', 'CmapTable', 'HheaTable', 'MaxpTable', 'HmtxTable', 'PostTable', 'OS2Table', 'LocaTable', 'GlyfTable']
}
}
})
]
},
plugins: [
new StringReplacePlugin(),
new webpack.BannerPlugin({
banner: banner,
raw: true
})
],
devtool: 'source-map'
};