-
Notifications
You must be signed in to change notification settings - Fork 62
/
webpack.plugin.config.js
246 lines (235 loc) · 6.51 KB
/
webpack.plugin.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
const path = require('path')
// eslint-disable-next-line
const PLUGIN_PATH = process.env.CE_COREPLUGINS || './plugins'
const webpack = require('webpack')
// eslint-disable-next-line
const glob = require('glob')
const uglifyjs = require('uglify-js')
// eslint-disable-next-line
const expose = require('expose-loader')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const fs = require('fs')
const entryPlus = require('webpack-entry-plus')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
var corePlugins = [
'org.ekstep.assessmentbrowser-1.1',
'org.ekstep.colorpicker-1.0',
'org.ekstep.conceptselector-1.1',
'org.ekstep.stage-1.0',
'org.ekstep.text-1.2',
'org.ekstep.shape-1.0',
'org.ekstep.video-1.5',
'org.ekstep.image-1.1',
'org.ekstep.audio-1.1',
'org.ekstep.hotspot-1.0',
'org.ekstep.scribblepad-1.0',
'org.ekstep.stageconfig-1.0',
'org.ekstep.telemetry-1.0',
'org.ekstep.preview-1.2',
'org.ekstep.activitybrowser-1.3',
'org.ekstep.collaborator-1.2',
'org.ekstep.download-1.0',
'org.ekstep.unsupported-1.0',
'org.ekstep.wordinfobrowser-1.0',
'org.ekstep.viewecml-1.0',
'org.ekstep.utils-1.0',
'org.ekstep.help-1.0',
'org.ekstep.editorstate-1.0',
'org.ekstep.contenteditorfunctions-1.2',
'org.ekstep.keyboardshortcuts-1.0',
'org.ekstep.richtext-1.0',
'org.ekstep.iterator-1.0',
'org.ekstep.navigation-1.0',
'org.ekstep.reviewercomments-1.0'
]
let entryFiles = []
function getEntryFiles () {
entryFiles = [{
entryFiles: packagePlugins(),
outputName: 'coreplugins.js'
},
{
entryFiles: getVendorCSS(),
outputName: 'plugin-vendor'
}
]
return entryPlus(entryFiles)
}
function packagePlugins () {
var pluginPackageArr = [] // Default coreplugin
pluginPackageArr.push('./content-editor/scripts/coreplugins.js')
corePlugins.forEach(function (plugin) {
var dependenciesArr = []
var manifest = JSON.parse(fs.readFileSync('plugins/' + plugin + '/manifest.json'))
var pluginContent = fs.readFileSync('plugins/' + plugin + '/editor/plugin.js', 'utf8')
if (fs.existsSync('plugins/' + plugin + '/editor/plugin.dist.js')) {
fs.unlinkSync('plugins/' + plugin + '/editor/plugin.dist.js')
}
if (manifest.editor.views && pluginContent) {
var controllerPathArr = []
var templatePathArr = []
manifest.editor.views.forEach(function (obj, i) {
controllerPathArr[i] = (obj.controller) ? 'require("' + obj.controller + '")' : undefined
templatePathArr[i] = (obj.template) ? 'require("' + obj.template + '")' : undefined
})
var count = 0
var len = (pluginContent.replace(/\b(loadNgModules)\b.*\)/g) || []).length
pluginContent = uglifyjs.minify(pluginContent.replace(/\b(loadNgModules)\b.*\)/g, function ($0) {
if (count === len) count = 0
var dash
dash = 'loadNgModules(' + templatePathArr[count] + ' , ' + controllerPathArr[count] + ', true)'
count++
return dash
}))
} else {
pluginContent = uglifyjs.minify(pluginContent)
}
if (manifest.editor.dependencies) {
manifest.editor.dependencies.forEach(function (obj, i) {
if (obj.type === 'js') {
dependenciesArr[i] = fs.readFileSync('./plugins/' + plugin + '/' + obj.src, 'utf8')
}
})
}
dependenciesArr.push('org.ekstep.pluginframework.pluginManager.registerPlugin(' + JSON.stringify(manifest) + ',' + pluginContent.code.replace(/;\s*$/, '') + ')')
fs.appendFile('plugins/' + plugin + '/editor/plugin.dist.js', [...dependenciesArr].join('\n'))
pluginPackageArr.push('./plugins/' + plugin + '/editor/plugin.dist.js')
})
return pluginPackageArr
}
function getVendorCSS () {
var cssDependencies = []
corePlugins.forEach(function (plugin) {
var manifest = JSON.parse(fs.readFileSync('plugins/' + plugin + '/manifest.json'))
if (manifest.editor.dependencies) {
manifest.editor.dependencies.forEach(function (dep) {
if (dep.type === 'css') {
cssDependencies.push('./plugins/' + plugin + '/' + dep.src)
}
})
};
})
return cssDependencies
}
module.exports = {
entry: getEntryFiles(),
output: {
filename: '[name]',
path: path.resolve(__dirname, './content-editor/scripts')
},
resolve: {
alias: {
'jquery': path.resolve('./node_modules/jquery/dist/jquery.js'),
'angular': path.resolve('./app/bower_components/angular/angular.js'),
'clipboard': path.resolve('./node_modules/clipboard/dist/clipboard.min.js'),
'E2EConverter': path.resolve('./plugins/org.ekstep.viewecml-1.0/editor/libs/src/converter.js'),
'xmlbuilder': path.resolve('./node_modules/xmlbuilder/lib/index.js'),
'X2JS': path.resolve('./plugins/org.ekstep.assessmentbrowser-1.1/editor/libs/xml2json.js'),
'video.js': path.resolve('./plugins/org.ekstep.video-1.5/editor/libs/video.js'),
'global/document': path.resolve('./node_modules/global/document.js'),
'global/window': path.resolve('./node_modules/global/window.js')
}
},
module: {
rules: [{
test: require.resolve('./plugins/org.ekstep.viewecml-1.0/editor/libs/src/converter.js'),
use: [{
loader: 'expose-loader',
options: 'E2EConverter'
}]
}, {
test: require.resolve('./plugins/org.ekstep.assessmentbrowser-1.1/editor/libs/xml2json.js'),
use: [{
loader: 'expose-loader',
options: 'X2JS'
}]
},
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
attrs: [':data-src']
}
}
},
{
test: /\.(s*)css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: false,
minimize: true,
'preset': 'advanced',
discardComments: {
removeAll: true
}
}
},
{
loader: 'sass-loader',
options: {
sourceMap: false,
minimize: true,
'preset': 'advanced',
discardComments: {
removeAll: true
}
}
}
]
}, {
test: /\.(gif|png|jpe?g|svg)$/,
use: [
'file-loader',
{
loader: 'url-loader',
options: {
limit: 50, // it's important
outputPath: './images/assets',
name: '[name].[ext]'
}
}
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].min.css'
}),
new webpack.ProvidePlugin({
E2EConverter: 'E2EConverter'
}),
new UglifyJsPlugin({
cache: false,
parallel: true,
uglifyOptions: {
compress: {
dead_code: true,
drop_console: false,
global_defs: {
DEBUG: true
},
passes: 1
},
ecma: 5,
mangle: true
},
sourceMap: true
})
],
optimization: {
minimize: true,
splitChunks: {
chunks: 'async',
minSize: 30000,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: '~'
}
}
}