-
Notifications
You must be signed in to change notification settings - Fork 33
/
webpack.config.js
196 lines (182 loc) · 5.42 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
"use strict";
var webpack = require("webpack");
var path = require("path");
var dts = require("dts-bundle");
var rimraf = require("rimraf");
var GenerateJsonPlugin = require("generate-json-webpack-plugin");
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");
// TODO add to dts_bundler
var dts_banner = [
"Type definitions for SurveyJS PDF library v" + packageJson.version,
"Copyright (c) 2015-" + year + " Devsoft Baltic OÜ - http://surveyjs.io/",
"Definitions by: Devsoft Baltic OÜ <https://github.com/surveyjs/>",
""
].join("\n");
var platformOptions = {
pdf: {
externals: {
jspdf: {
root: "jspdf",
commonjs2: "jspdf",
commonjs: "jspdf",
amd: "jspdf"
},
"survey-core": {
root: "Survey",
commonjs2: "survey-core",
commonjs: "survey-core",
amd: "survey-core"
}
},
keywords: ["pdf"],
peerDependencies: {
"survey-core": packageJson.version
},
dependencies: {
jspdf: "^2.3.0",
}
}
};
module.exports = function(options) {
//TODO
options.platformPrefix = options.platform;
var packagePath = "./packages/survey-" + options.platform + "/";
var percentage_handler = function handler(percentage, msg) {
if (0 === percentage) {
console.log("Build started... good luck!");
} else if (1 === percentage) {
if (options.buildType === "prod") {
dts.bundle({
name: "../../survey." + options.platformPrefix,
main: packagePath + "typings/entries/" + options.platform + ".d.ts",
outputAsModuleFolder: true,
headerText: dts_banner
});
rimraf.sync(packagePath + "typings");
fs.createReadStream("./LICENSE").pipe(
fs.createWriteStream(packagePath + "LICENSE")
);
fs.createReadStream("./README.md").pipe(
fs.createWriteStream(packagePath + "README.md")
);
}
}
};
var mainFile = "survey." + options.platformPrefix + ".js";
var packagePlatformJson = {
name: "survey-" + options.platform,
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"].concat(
platformOptions[options.platform].keywords
),
homepage: "https://surveyjs.io/",
license: "SEE LICENSE IN LICENSE",
files: [
"survey." + options.platformPrefix + ".d.ts",
"survey." + options.platformPrefix + ".js",
"survey." + options.platformPrefix + ".min.js",
"survey." + options.platformPrefix + ".fonts.js",
"survey." + options.platformPrefix + ".fonts.min.js" ],
main: mainFile,
repository: {
type: "git",
url: "https://github.com/surveyjs/survey-pdf.git"
},
typings: "survey." + options.platformPrefix + ".d.ts"
};
if (!!platformOptions[options.platform].dependencies) {
packagePlatformJson.dependencies =
platformOptions[options.platform].dependencies;
}
if (!!platformOptions[options.platform].peerDependencies) {
packagePlatformJson.peerDependencies =
platformOptions[options.platform].peerDependencies;
}
var config = {
entry: {},
resolve: {
extensions: [".ts", ".js", ".tsx"],
alias: {
tslib: path.join(__dirname, "./src/entries/helpers.ts")
}
},
module: {
rules: [
{
test: /\.(ts)$/,
use: {
loader: "ts-loader",
options: {
compilerOptions: {
declaration: options.buildType === "prod",
outDir: packagePath + "typings/"
}
}
}
},
{
test: /\.svg/,
use: { loader: "url-loader" }
},
{
test: /\.html$/,
use: { loader: "html-loader" }
}
]
},
output: {
filename:
packagePath +
"[name]" +
(options.buildType === "prod" ? ".min" : "") +
".js",
library: options.libraryName || "SurveyPDF",
libraryTarget: "umd",
umdNamedDefine: true
},
externals: platformOptions[options.platform].externals,
plugins: [
new webpack.ProgressPlugin(percentage_handler),
new webpack.DefinePlugin({
"process.env.ENVIRONMENT": JSON.stringify(options.buildType),
"process.env.VERSION": JSON.stringify(packageJson.version)
}),
new webpack.BannerPlugin({
banner: banner
})
],
devtool: "inline-source-map"
};
if (options.buildType === "prod") {
config.devtool = false;
config.plugins = config.plugins.concat([
new webpack.optimize.UglifyJsPlugin(),
new GenerateJsonPlugin(
packagePath + "package.json",
packagePlatformJson,
undefined,
2
)
]);
}
if (options.buildType === "dev") {
config.plugins = config.plugins.concat([
new webpack.LoaderOptionsPlugin({ debug: true })
]);
}
config.entry["survey." + options.platform] = path.resolve(
__dirname,
"./src/entries/" + options.platform
);
return config;
};