forked from surveyjs/custom-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
186 lines (169 loc) · 4.7 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
"use strict";
var webpack = require("webpack");
var path = require("path");
var FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin");
var CopyWebpackPlugin = require("copy-webpack-plugin");
const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin');
var CleanWebpackPlugin = require("clean-webpack-plugin");
var packageJson = require("./package.json");
const today = new Date();
const year = today.getFullYear();
var copyright = [
"surveyjs-widgets - Widgets for the SurveyJS 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");
var outputFolder = "package";
var main = "surveyjs-widgets";
var widgets = [
main,
"select2",
"select2-tagbox",
"jquery-ui-datepicker",
"inputmask",
"icheck",
"jquery-bar-rating",
"sortablejs",
"nouislider",
"ck-editor",
"easy-autocomplete",
"pretty-checkbox",
"bootstrap-slider",
"microphone",
"emotionsratings"
];
var dependencies = {
select2: "^4.0.4",
icheck: "^1.0.2",
"jquery-ui": "^1.12.1",
sortablejs: "^1.6.1",
nouislider: "^14.6.3",
inputmask: "^5.0.3",
"jquery-bar-rating": "^1.2.2",
"easy-autocomplete": "^1.3.5",
"pretty-checkbox": "^3.0.3",
"bootstrap-slider": "^10.0.0",
recordrtc: "^5.4.6",
"emotion-ratings": "^2.0.1"
};
var entry = {};
module.exports = function (options) {
var packagePath = `./${outputFolder}`;
var targetPackageJson = {
name: `surveyjs-widgets`,
version: packageJson.version,
description: "Custom widgets for the SurveyJS library",
keywords: [
"Survey",
"JavaScript",
"Bootstrap",
"Library",
"SurveyJS",
"Widgets"
],
homepage: "https://surveyjs.io/",
license: "MIT",
files: [],
main: main + ".js",
repository: {
type: "git",
url: "https://github.com/surveyjs/widgets.git"
},
dependencies: {
jquery: "^3.2.1"
},
peerDependencies: {}
};
widgets.forEach(function (widget) {
if (widget !== main) {
targetPackageJson.files.push(`widgets/${widget}.js`);
targetPackageJson.files.push(`widgets/${widget}.min.js`);
targetPackageJson.files.push(`widgets/${widget}.min.js.map`);
entry["widgets/" + widget] = path.join(__dirname, `./src/${widget}.js`);
} else {
targetPackageJson.files.push(`${widget}.js`);
targetPackageJson.files.push(`${widget}.min.js`);
targetPackageJson.files.push(`${widget}.min.js.map`);
entry[widget] = path.join(__dirname, `./src/${widget}.js`);
}
});
targetPackageJson.dependencies = Object.assign(
targetPackageJson.dependencies,
dependencies
);
var config = {
entry: entry,
output: {
path: path.join(__dirname, packagePath),
filename: `[name].${options.buildType === "prod" ? "min." : ""}js`,
library: "[name]",
libraryTarget: "umd",
umdNamedDefine: true
},
externals: {
jquery: {
root: "jQuery",
commonjs2: "jquery",
commonjs: "jquery",
amd: "jquery"
},
inputmask: {
root: "Inputmask",
commonjs2: "inputmask",
commonjs: "inputmask",
amd: "inputmask"
},
nouislider: {
root: "noUiSlider",
commonjs2: "nouislider",
commonjs: "nouislider",
amd: "nouislider"
},
sortablejs: {
root: "Sortable",
commonjs2: "sortablejs",
commonjs: "sortablejs",
amd: "sortablejs"
},
"bootstrap-slider": {
root: "Slider",
commonjs2: "bootstrap-slider",
commonjs: "bootstrap-slider",
amd: "bootstrap-slider"
}
},
optimization: {
minimize: options.buildType === "prod"
},
mode: options.buildType === "prod" ? "production" : "development",
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new FriendlyErrorsWebpackPlugin()
],
devtool: options.buildType === "prod" ? "source-map" : "inline-source-map",
devServer: {
contentBase: path.join(__dirname, outputFolder),
open: true
}
};
if (options.buildType === "dev") {
config.plugins = config.plugins.concat([
new CleanWebpackPlugin([outputFolder], { verbose: true })
]);
}
if (options.buildType === "prod") {
config.plugins = config.plugins.concat([
new webpack.BannerPlugin(copyright),
new GeneratePackageJsonPlugin(targetPackageJson),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, "./src/targetREADME.md"),
to: path.join(__dirname, `${packagePath}/README.md`)
}
]
})
]);
}
return config;
};