@@ -4,18 +4,22 @@ var webpack = require("webpack");
44var path = require ( "path" ) ;
55var FriendlyErrorsWebpackPlugin = require ( "friendly-errors-webpack-plugin" ) ;
66const VirtualModulePlugin = require ( "virtual-module-webpack-plugin" ) ;
7+ var CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
8+ var GenerateJsonPlugin = require ( 'generate-json-webpack-plugin' ) ;
79
810var packageJson = require ( "./package.json" ) ;
911var 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" ;
1618var commonDependencies = {
1719 'select2' : '>=^4.0.4'
1820} ;
21+ var widgets = [ "select2" , "imagepicker" , "icheck" , "datepicker" , "tagbox" ] ;
22+ var entry = { } ;
1923
2024var 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+
8393module . 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