-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathwebpack.config.js
170 lines (157 loc) · 4.38 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
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
"use strict";
var webpack = require("webpack");
var path = require("path");
var packageJson = require("./package.json");
var fs = require("fs");
const today = new Date();
const year = today.getFullYear();
var banner = [
"surveyjs - SurveyJS PDF library v" + packageJson.version,
"Copyright (c) 2015-" + year + " Devsoft Baltic OÜ - http://surveyjs.io/",
"License: MIT (http://www.opensource.org/licenses/mit-license.php)"
].join("\n");
const buildPlatformJson = {
name: "survey-pdf",
version: packageJson.version,
description:
"survey.pdf.js is a SurveyJS PDF Library. It is a easy way to export SurveyJS surveys to PDF. It uses JSON for survey metadata.",
keywords: ["Survey", "JavaScript", "PDF", "Library", "pdf"],
homepage: "https://surveyjs.io/",
license: "SEE LICENSE IN LICENSE",
module: "fesm/survey.pdf.mjs",
main: "survey.pdf.js",
repository: {
type: "git",
url: "https://github.com/surveyjs/survey-pdf.git"
},
typings: "./typings/entries/pdf.d.ts",
peerDependencies: {
"survey-core": packageJson.version
},
dependencies: {
jspdf: "^2.3.0 || ^3"
},
exports: {
".": {
"types": "./typings/entries/pdf.d.ts",
"import": "./fesm/survey.pdf.mjs",
"require": "./survey.pdf.js"
},
"./survey.pdf.fonts": {
"import": "./fesm/survey.pdf.fonts.mjs",
"require": "./survey.pdf.fonts.js"
},
}
}
function getPercentageHandler(emitNonSourceFiles, buildPath) {
return function (percentage, msg) {
if (0 === percentage) {
console.log("Build started... good luck!");
} else if (1 === percentage) {
if (emitNonSourceFiles) {
fs.createReadStream("./LICENSE").pipe(
fs.createWriteStream(buildPath + "/LICENSE")
);
fs.createReadStream("./README.md").pipe(
fs.createWriteStream(buildPath + "/README.md")
);
fs.writeFileSync(
buildPath + "/package.json",
JSON.stringify(buildPlatformJson, null, 2),
"utf8"
);
}
}
};
}
module.exports = function (options) {
const emitDeclarations = !!options.emitDeclarations;
const emitNonSourceFiles = !!options.emitNonSourceFiles;
var buildPath = path.resolve(__dirname, "./build");
var config = {
mode: options.buildType === "prod" ? "production" : "development",
entry: {},
resolve: {
extensions: [".ts", ".js", ".tsx"],
alias: {
tslib: path.join(__dirname, "./src/entries/helpers.ts")
}
},
module: {
rules: [
{
test: /\.(ts)$/,
use: {
loader: "ts-loader",
options: {
configFile: options.tsConfigFile || "tsconfig.json",
compilerOptions: {
declaration: emitDeclarations,
declarationDir: emitDeclarations ? buildPath + "/typings/" : null
}
}
}
},
{
test: /\.svg/,
use: { loader: "url-loader" }
},
{
test: /\.html$/,
use: { loader: "html-loader" }
}
]
},
output: {
path: buildPath,
filename:
"[name]" +
(options.buildType === "prod" ? ".min" : "") +
".js",
library: options.libraryName || "SurveyPDF",
libraryTarget: "umd",
umdNamedDefine: true
},
externals: {
jspdf: {
root: "jspdf",
commonjs2: "jspdf",
commonjs: "jspdf",
amd: "jspdf"
},
"survey-core": {
root: "Survey",
commonjs2: "survey-core",
commonjs: "survey-core",
amd: "survey-core"
}
},
plugins: [
new webpack.ProgressPlugin(getPercentageHandler(emitNonSourceFiles, buildPath)),
new webpack.DefinePlugin({
"process.env.ENVIRONMENT": JSON.stringify(options.buildType),
"process.env.VERSION": JSON.stringify(packageJson.version)
}),
new webpack.BannerPlugin({
banner: banner
})
],
devtool: "source-map"
};
if (options.buildType === "prod") {
config.devtool = false;
config.optimization = {
minimize: options.buildType === "prod",
};
}
if (options.buildType === "dev") {
config.plugins = config.plugins.concat([
new webpack.LoaderOptionsPlugin({ debug: true })
]);
}
config.entry["survey." + "pdf"] = path.resolve(
__dirname,
"./src/entries/" + "pdf"
);
return config;
};