Skip to content

Commit 22e1a0c

Browse files
added webpack config for package.json, README and maps;
fixed import survey for some widgets;
1 parent 4a09a36 commit 22e1a0c

File tree

6 files changed

+108
-36
lines changed

6 files changed

+108
-36
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
},
1818
"private": true,
1919
"devDependencies": {
20+
"copy-webpack-plugin": "^4.1.1",
2021
"friendly-errors-webpack-plugin": "^1.6.1",
22+
"generate-json-webpack-plugin": "^0.2.2",
2123
"survey-angular": "^0.12.31",
2224
"survey-jquery": "^0.12.31",
2325
"survey-knockout": "^0.12.31",

src/datepicker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "./utils/surveyjs_importer.js";
1+
import "./surveyjs_importer.js";
22

33
var widget = {
44
name: "datepicker",

src/icheck.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "./utils/surveyjs_importer.js";
1+
import "./surveyjs_importer.js";
22

33
var widget = {
44
className: "iradio_square-blue",

src/npmREADME.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Custom Widgets for the SurveyJS library
2+
3+
##Getting started
4+
[![Join the chat at https://gitter.im/andrewtelnov/surveyjs](https://badges.gitter.im/andrewtelnov/surveyjs.svg)](https://gitter.im/andrewtelnov/surveyjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5+
6+
To find our examples go to the [surveyjs.io site](e.g. https://surveyjs.io/Examples/Library/?id=custom-widget-select2)
7+
8+
##License
9+
10+
MIT license - [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)
11+
12+
##SurveyJS library
13+
14+
SurveyJS library sources are [here](https://github.com/surveyjs/surveyjs)
15+
16+
##Visual Editor
17+
18+
Visual Editor sources are [here](https://github.com/surveyjs/editor)

src/tagbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "./utils/surveyjs_importer.js";
1+
import "./surveyjs_importer.js";
22

33
var widget = {
44
name: "tagbox",

webpack.config.js

Lines changed: 85 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ var webpack = require("webpack");
44
var path = require("path");
55
var FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin");
66
const VirtualModulePlugin = require("virtual-module-webpack-plugin");
7+
var CopyWebpackPlugin = require('copy-webpack-plugin');
8+
var GenerateJsonPlugin = require('generate-json-webpack-plugin');
79

810
var packageJson = require("./package.json");
911
var copyright = [
10-
"surveyjs-widgets - Widgets for SurveyJS library v" + packageJson.version,
12+
"surveyjs-widgets - Widgets for the SurveyJS library v" + packageJson.version,
1113
"Copyright (c) 2015-2017 Devsoft Baltic OÜ - http://surveyjs.io/",
1214
"License: MIT (http://www.opensource.org/licenses/mit-license.php)",
1315
].join("\n");
14-
var outputFolder = "packages";
1516

17+
var outputFolder = "packages";
1618
var commonDependencies = {
1719
'select2': '>=^4.0.4'
1820
};
21+
var widgets = ["select2", "imagepicker", "icheck", "datepicker", "tagbox"];
22+
var entry = {};
1923

2024
var platformOptions = {
2125
'react': {
@@ -28,7 +32,8 @@ var platformOptions = {
2832
}
2933
},
3034
import: 'import * as Survey from "survey-react";',
31-
dependencies: { 'survey-react': '>=^0.12.32' }
35+
dependencies: { 'survey-react': '>=^0.12.32' },
36+
keywords: ['react', 'react-component']
3237
},
3338
'knockout': {
3439
externals: {
@@ -40,7 +45,8 @@ var platformOptions = {
4045
}
4146
},
4247
import: 'import * as Survey from "survey-knockout";',
43-
dependencies: { 'survey-knockout': '>=^0.12.32' }
48+
dependencies: { 'survey-knockout': '>=^0.12.32' },
49+
keywords: ['knockout']
4450
},
4551
'jquery': {
4652
externals: {
@@ -52,7 +58,8 @@ var platformOptions = {
5258
}
5359
},
5460
import: 'import * as Survey from "survey-jquery";',
55-
dependencies: { 'survey-jquery': '>=^0.12.32' }
61+
dependencies: { 'survey-jquery': '>=^0.12.32' },
62+
keywords: ['jquery', 'jquery-plugin']
5663
},
5764
'angular': {
5865
externals: {
@@ -64,7 +71,8 @@ var platformOptions = {
6471
}
6572
},
6673
import: 'import * as Survey from "survey-angular";',
67-
dependencies: { 'survey-angular': '>=^0.12.32' }
74+
dependencies: { 'survey-angular': '>=^0.12.32' },
75+
keywords: ['angular', 'angular-component']
6876
},
6977
'vue': {
7078
externals: {
@@ -76,52 +84,96 @@ var platformOptions = {
7684
}
7785
},
7886
import: 'import * as Survey from "survey-vue";',
79-
dependencies: { 'survey-vue': '>=^0.12.32' }
87+
dependencies: { 'survey-vue': '>=^0.12.32' },
88+
keywords: ['vue']
8089
}
8190
};
8291

92+
8393
module.exports = function(options) {
84-
var config = {
85-
entry: {
86-
select2: path.join(__dirname, `./src/select2.js`),
87-
imagepicker: path.join(__dirname, "./src/imagepicker.js")
88-
},
94+
var packagePath = `./${outputFolder}/survey-cw-${options.platform}`;
95+
var packagePlatformJson = {
96+
'name': packagePath,
97+
'version': packageJson.version,
98+
'description': 'Custom widgets for the SurveyJS library',
99+
'keywords': [
100+
'Survey',
101+
'JavaScript',
102+
'Bootstrap',
103+
'Library'
104+
].concat(platformOptions[options.platform].keywords),
105+
'homepage': 'https://surveyjs.io/',
106+
'license': 'MIT',
107+
'files': [],
108+
'repository': {
109+
'type': 'git',
110+
'url': 'https://github.com/surveyjs/widgets.git'
111+
}
112+
};
113+
114+
widgets.forEach(function(widget) {
115+
packagePlatformJson.files.push(`${widget}.js`);
116+
packagePlatformJson.files.push(`${widget}.min.js`);
117+
packagePlatformJson.files.push(`${widget}.min.js.map`);
118+
entry[widget] = path.join(__dirname, `./src/${widget}.js`);
119+
})
120+
121+
if(!!platformOptions[options.platform].dependencies) {
122+
packagePlatformJson.dependencies = platformOptions[options.platform].dependencies;
123+
}
124+
if(!!platformOptions[options.platform].peerDependencies) {
125+
packagePlatformJson.peerDependencies = platformOptions[options.platform].peerDependencies;
126+
}
127+
packagePlatformJson.dependencies = Object.assign(packagePlatformJson.dependencies, commonDependencies);
128+
129+
var config = {
130+
entry: entry,
89131
output: {
90-
path: path.join(__dirname, `./${outputFolder}/survey-cw-${options.platform}`),
91-
filename: `[name].${options.buildType === "prod" ? "min." : ""}js`,
92-
library: "[name]",
93-
libraryTarget: "umd",
94-
umdNamedDefine: true
132+
path: path.join(__dirname, packagePath),
133+
filename: `[name].${options.buildType === "prod" ? "min." : ""}js`,
134+
library: "[name]",
135+
libraryTarget: "umd",
136+
umdNamedDefine: true
95137
},
96138
externals: platformOptions[options.platform].externals,
97139
plugins: [
98-
new webpack.NoEmitOnErrorsPlugin(),
99-
new webpack.BannerPlugin(copyright),
100-
new FriendlyErrorsWebpackPlugin(),
101-
new webpack.DefinePlugin({
140+
new webpack.NoEmitOnErrorsPlugin(),
141+
new FriendlyErrorsWebpackPlugin(),
142+
new webpack.DefinePlugin({
102143
'PLATFORM': JSON.stringify(options.platform)
103-
}),
104-
new VirtualModulePlugin({
144+
}),
145+
new VirtualModulePlugin({
105146
moduleName: 'src/surveyjs_importer.js',
106147
contents: platformOptions[options.platform].import
107-
})
148+
})
108149
],
109150
devtool: options.buildType === "prod" ? "source-map" : "inline-source-map",
110151
devServer: {
111-
contentBase: path.join(__dirname, outputFolder),
112-
open: true
152+
contentBase: path.join(__dirname, outputFolder),
153+
open: true
113154
}
114-
};
155+
};
115156

116-
117-
if (options.buildType === "prod") {
157+
158+
if (options.buildType === "prod") {
118159
config.plugins = config.plugins.concat([
119-
new webpack.optimize.UglifyJsPlugin({
160+
new webpack.optimize.UglifyJsPlugin({
120161
unused: true,
121162
dead_code: true
122-
})
163+
}),
164+
new webpack.BannerPlugin(copyright),
165+
new GenerateJsonPlugin(
166+
'package.json',
167+
packagePlatformJson,
168+
undefined,
169+
2
170+
),
171+
new CopyWebpackPlugin([{
172+
from: path.join(__dirname, './src/npmREADME.md'),
173+
to: path.join(__dirname, `${packagePath}/README.md`)
174+
}])
123175
]);
124-
}
176+
}
125177

126-
return config;
178+
return config;
127179
};

0 commit comments

Comments
 (0)