forked from surveyjs/survey-creator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
191 lines (181 loc) · 5.92 KB
/
webpack.config.js
File metadata and controls
191 lines (181 loc) · 5.92 KB
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
'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 banner = [
"surveyjs Editor v" + packageJson.version,
"(c) Devsoft Baltic O� - http://surveyjs.io/",
"Github - https://github.com/surveyjs/editor",
"License: (http://editor.surveyjs.io/license.html)"
].join("\n");
var dts_banner = ["Type definitions for Surveyjs Editor JavaScript library v" + packageJson.version,
"(c) Devsoft Baltic O� - http://surveyjs.io/",
"Github - https://github.com/surveyjs/editor",
"License: (http://editor.surveyjs.io/license.html)",
""].join("\n");
var packagePlatformJson = {
"name": "surveyjs-editor",
"version": packageJson.version,
"description": "Use surveyjs Editor to create or edit JSON for surveyjs library.",
"keywords": [
"Survey",
"JavaScript",
"Editor",
"surveyjs"
],
"homepage": "http://editor.surveyjs.io",
"license": "http://editor.surveyjs.io/license.html",
"files": [
"surveyeditor.css",
"surveyeditor.js",
"surveyeditor.d.ts",
"surveyeditor.min.js"
],
"main": "surveyeditor.min.js",
"repository": {
"type": "git",
"url": "https://github.com/surveyjs/editor.git"
},
"engines": {
"node": ">=0.10.0"
},
'typings': 'surveyeditor.d.ts',
"dependencies": {
"survey-knockout": "^" + packageJson.version,
"jquery": "^2.1.0",
"knockout": "^3.4.0",
"bootstrap": "^3.3.6",
"ace-builds": "^1.2.2"
},
"devDependencies": {
"@types/knockout": "^3.4.0"
}
};
module.exports = function(options) {
var packagePath = './package/';
var extractCSS = new ExtractTextPlugin({ filename: packagePath + 'surveyeditor.css' });
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: '../../surveyeditor',
main: packagePath + 'typings/entries/index.d.ts',
outputAsModuleFolder: true,
headerText: dts_banner
});
rimraf.sync(packagePath + 'typings');
fs.createReadStream('./npmREADME.md').pipe(fs.createWriteStream(packagePath + 'README.md'));
}
}
};
var config = {
entry: {
'surveyeditor': path.resolve(__dirname, './src/entries/index.ts')
},
resolve: {
extensions: ['.ts', '.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',
loader: 'css-loader!sass-loader'
})
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.svg/,
use: {
loader: 'url-loader',
options: {}
}
}
]
},
output: {
filename: packagePath + '[name]' + (options.buildType === 'prod' ? '.min': '') + '.js',
library: 'SurveyEditor',
libraryTarget: 'umd',
umdNamedDefine: true
},
externals: {
'jquery': {
root: 'jQuery',
commonjs2: 'jquery',
commonjs: 'jquery',
amd: 'jquery'
},
'knockout': {
root: 'ko',
commonjs2: 'knockout',
commonjs: 'knockout',
amd: 'knockout'
},
'bootstrap': {
root: 'bootstrap',
commonjs2: 'bootstrap',
commonjs: 'bootstrap',
amd: 'bootstrap'
},
'survey-knockout': {
root: 'Survey',
commonjs2: 'survey-knockout',
commonjs: 'survey-knockout',
amd: 'survey-knockout'
}
},
plugins: [
new webpack.ProgressPlugin(percentage_handler),
new webpack.DefinePlugin({
"process.env.ENVIRONMENT": JSON.stringify(options.buildType),
"process.env.VERSION": JSON.stringify(packageJson.version)
}),
extractCSS
],
devtool: 'inline-source-map'
};
if (options.buildType === 'prod') {
config.devtool = false;
config.plugins = config.plugins.concat([
new webpack.optimize.UglifyJsPlugin(),
new webpack.BannerPlugin(banner),
new GenerateJsonPlugin(
packagePath + 'package.json',
packagePlatformJson,
undefined,
2
)
]);
}
if (options.buildType === 'dev') {
config.plugins = config.plugins.concat([
new webpack.LoaderOptionsPlugin({ debug: true})
]);
}
return config;
};