This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
forked from surveyjs/survey-creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
329 lines (311 loc) · 8.56 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
"use strict";
var webpack = require("webpack");
var path = require("path");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
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");
var replace = require("replace-in-file");
var svgStoreUtils = require(path.resolve(
__dirname,
"./node_modules/webpack-svgstore-plugin/src/helpers/utils.js"
));
var banner = [
"SurveyJS Creator v" + packageJson.version,
"(c) Devsoft Baltic O� - http://surveyjs.io/",
"Github: https://github.com/surveyjs/survey-creator",
"License: https://surveyjs.io/Licenses#BuildSurvey"
].join("\n");
var dts_banner = [
"Type definitions for SurveyJS Creator JavaScript library v" +
packageJson.version,
"(c) Devsoft Baltic O� - http://surveyjs.io/",
"Github: https://github.com/surveyjs/survey-creator",
"License: https://surveyjs.io/Licenses#BuildSurvey",
""
].join("\n");
var packagePlatformJson = {
name: "surveyjs-editor",
version: packageJson.version,
description:
"Use SurveyJS Creator to create or edit JSON for SurveyJS Library.",
keywords: [
"Survey",
"Survey Creator",
"Form Builder",
"Survey Maker",
"SurveyJS",
"JavaScript",
"TypeScript"
],
homepage: "https://surveyjs.io/Overview/Survey-Creator",
license: "https://surveyjs.io/Licenses#BuildSurvey",
files: [
"surveyeditor.css",
"surveyeditor.min.css",
"surveyeditor.js",
"surveyeditor.d.ts",
"surveyeditor.min.js"
],
main: "surveyeditor.js",
repository: {
type: "git",
url: "https://github.com/surveyjs/survey-creator.git"
},
engines: {
node: ">=0.10.0"
},
typings: "surveyeditor.d.ts",
peerDependencies: {
bootstrap: "^3.3.6",
jquery: "^3.1.1",
"ace-builds": "^1.2.2"
},
dependencies: {
"survey-knockout": "^" + packageJson.version,
knockout: "^3.4.0",
"@types/knockout": "^3.4.0"
},
devDependencies: {}
};
var buildPlatformJson = {
name: "survey-creator",
version: packageJson.version,
description:
"Use SurveyJS Creator to create or edit JSON for SurveyJS Library.",
keywords: [
"Survey",
"Survey Creator",
"Form Builder",
"Survey Maker",
"SurveyJS",
"JavaScript",
"TypeScript"
],
homepage: "https://surveyjs.io/Overview/Survey-Creator",
license: "https://surveyjs.io/Licenses#BuildSurvey",
files: [
"survey-creator.css",
"survey-creator.min.css",
"survey-creator.js",
"survey-creator.d.ts",
"survey-creator.min.js"
],
main: "survey-creator.js",
repository: {
type: "git",
url: "https://github.com/surveyjs/survey-creator.git"
},
engines: {
node: ">=0.10.0"
},
typings: "survey-creator.d.ts",
peerDependencies: {
bootstrap: "^3.3.6",
jquery: "^3.1.1",
"ace-builds": "^1.2.2"
},
dependencies: {
"survey-knockout": "^" + packageJson.version,
knockout: "^3.4.0",
"@types/knockout": "^3.4.0"
},
devDependencies: {}
};
module.exports = function(options) {
var packagePath = "./package/";
var buildPath = "./build/";
var extractCSS = new ExtractTextPlugin({
filename:
packagePath +
(options.buildType === "prod"
? "surveyeditor.min.css"
: "surveyeditor.css")
});
function createSVGBundle() {
var options = {
fileName: path.resolve(__dirname, "./src/svgbundle.html"),
template: path.resolve(__dirname, "./svgbundle.pug"),
svgoOptions: {
plugins: [{ removeTitle: true }]
},
prefix: "icon-"
};
svgStoreUtils.filesMap(path.join("./src/images/**/*.svg"), files => {
const fileContent = svgStoreUtils.createSprite(
svgStoreUtils.parseFiles(files, options),
options.template
);
fs.writeFileSync(options.fileName, fileContent);
});
}
var percentage_handler = function handler(percentage, msg) {
if (0 == percentage) {
console.log("Build started... good luck!");
createSVGBundle();
} else if (1 == percentage) {
if (options.buildType === "prod") {
dts.bundle({
name: "../../surveyeditor",
main: packagePath + "typings/entries/index.d.ts",
outputAsModuleFolder: true,
headerText: dts_banner
});
replace.sync(
{
files: packagePath + "surveyeditor.d.ts",
from: /export let\s+\w+:\s+\w+;/,
to: ""
},
(error, changes) => {
if (error) {
return console.error("Error occurred:", error);
}
console.log("check me : " + packagePath + "surveyeditor.d.ts");
console.log("Modified files:", changes.join(", "));
}
);
rimraf.sync(packagePath + "typings");
fs.createReadStream("./README.md").pipe(
fs.createWriteStream(packagePath + "README.md")
);
}
if (options.libraryName === "SurveyCreator") {
if (!fs.existsSync(buildPath)) {
fs.mkdirSync(buildPath);
}
function copyToBuild(oldFile, newFile) {
fs.createReadStream(packagePath + oldFile).pipe(
fs.createWriteStream(buildPath + newFile)
);
}
if (options.buildType === "prod") {
copyToBuild("surveyeditor.min.js", "survey-creator.min.js");
copyToBuild("surveyeditor.min.css", "survey-creator.min.css");
copyToBuild("surveyeditor.d.ts", "survey-creator.d.ts");
fs.createReadStream("./README.md").pipe(
fs.createWriteStream(buildPath + "README.md")
);
fs.writeFileSync(
buildPath + "package.json",
JSON.stringify(buildPlatformJson, null, 2),
"utf8"
);
} else {
copyToBuild("surveyeditor.js", "survey-creator.js");
copyToBuild("surveyeditor.css", "survey-creator.css");
}
}
}
};
var config = {
entry: {
surveyeditor: path.resolve(__dirname, "./src/entries/index.ts")
},
resolve: {
extensions: [".ts", ".js", ".tsx", ".scss"],
alias: {
tslib: path.join(__dirname, "./src/entries/helpers.ts")
}
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
loader: "ts-loader",
options: {
compilerOptions: {
declaration: options.buildType === "prod",
outDir: packagePath + "typings/"
}
}
},
{
test: /\.scss$/,
loader: extractCSS.extract({
fallbackLoader: "style-loader",
use: [
{
loader: "css-loader",
options: {
minimize: options.buildType === "prod"
}
},
{
loader: "sass-loader"
}
]
})
},
{
test: /\.html$/,
loader: "html-loader"
},
{
test: /\.(svg|png)$/,
use: {
loader: "url-loader",
options: {}
}
}
]
},
output: {
filename:
packagePath +
"[name]" +
(options.buildType === "prod" ? ".min" : "") +
".js",
library: options.libraryName || "SurveyEditor",
libraryTarget: "umd",
umdNamedDefine: true
},
externals: {
knockout: {
root: "ko",
commonjs2: "knockout",
commonjs: "knockout",
amd: "knockout"
},
"survey-knockout": {
root: "Survey",
commonjs2: "survey-knockout",
commonjs: "survey-knockout",
amd: "survey-knockout"
}
},
plugins: [
new webpack.WatchIgnorePlugin([/svgbundle\.html/]),
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
}),
extractCSS
],
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 })
]);
}
return config;
};