forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.build.javascript.js
More file actions
160 lines (150 loc) · 3.81 KB
/
script.build.javascript.js
File metadata and controls
160 lines (150 loc) · 3.81 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
process.env.BABEL_ENV = 'production'
var
fs = require('fs'),
zlib = require('zlib'),
rollup = require('rollup'),
uglify = require('uglify-js'),
babel = require('rollup-plugin-babel'),
string = require('rollup-plugin-string'),
vue = require('rollup-plugin-vue'),
nonStandalone = process.argv[2] === 'simple' || process.argv[3] === 'simple',
version = process.env.VERSION || require('../package.json').version,
file,
banner =
'/*!\n' +
' * Quasar Framework v' + version + '\n' +
' * (c) ' + new Date().getFullYear() + ' Razvan Stoenescu\n' +
' * Released under the MIT License.\n' +
' */',
babelConfig = {
exclude: 'node_modules/**'
},
stringConfig = {
include: ['**/*.svg', '**/*.html']
},
external = [
'fastclick',
'hammerjs',
'moment',
'velocity-animate',
'velocity-animate/velocity.ui'
],
globals = {
fastclick: 'FastClick',
hammerjs: 'Hammer',
moment: 'moment',
'velocity-animate': 'Velocity',
'velocity-animate/velocity.ui': 'velui'
},
rollupConfig = {
entry: 'src/index.js',
plugins: [vue(), string(stringConfig), babel(babelConfig)],
external: external
}
'index index.es6'.split(' ').forEach(function (name) { // eslint-disable-line
file = fs
.readFileSync('src/' + name + '.js', 'utf-8')
.replace(/version: '[\d\.]+'/, "version: '" + version + "'")
fs.writeFileSync('src/' + name + '.js', file)
})
// CommonJS build.
rollup
.rollup(rollupConfig)
.then(function (bundle) {
return write('dist/quasar.common.js', bundle.generate({
format: 'cjs',
banner: banner,
globals: globals
}).code)
})
// ES6 Dev Build
.then(function () {
return rollup
.rollup({
entry: 'src/index.es6.js',
plugins: [vue(), string(stringConfig)],
external: external
})
.then(function (bundle) {
return write('dist/quasar.es6.js', bundle.generate({
exports: 'named',
banner: banner,
globals: globals
}).code)
})
})
// Standalone Dev Build
.then(function () {
if (nonStandalone) {
return
}
return rollup.rollup(rollupConfig)
.then(function (bundle) {
return write('dist/quasar.standalone.js', bundle.generate({
format: 'umd',
banner: banner,
moduleName: 'Quasar',
globals: globals
}).code)
})
})
// Standalone Production Build
.then(function () {
if (nonStandalone) {
return
}
return rollup.rollup(rollupConfig)
.then(function (bundle) {
var code, res, map
code = bundle.generate({
format: 'umd',
moduleName: 'Quasar',
banner: banner,
globals: globals
}).code
res = uglify.minify(code, {
fromString: true,
outSourceMap: 'quasar.standalone.min.js.map',
output: {
preamble: banner,
ascii_only: true
}
})
// fix uglifyjs sourcemap
map = JSON.parse(res.map)
map.sources = ['quasar.standalone.js']
map.sourcesContent = [code]
map.file = 'quasar.standalone.min.js'
return [
write('dist/quasar.standalone.min.js', res.code),
write('dist/quasar.standalone.min.js.map', JSON.stringify(map))
]
})
.then(zip)
})
.catch(function (e) {
console.log(e)
})
function write (dest, code) {
return new Promise(function (resolve, reject) {
fs.writeFile(dest, code, function (err) {
if (err) return reject(err)
console.log(dest.bold + ' ' + getSize(code).gray)
resolve()
})
})
}
function zip () {
return new Promise(function (resolve, reject) {
fs.readFile('dist/quasar.standalone.min.js', function (err, buf) {
if (err) return reject(err)
zlib.gzip(buf, function (err, buf) {
if (err) return reject(err)
write('dist/quasar.standalone.min.js.gz', buf).then(resolve)
})
})
})
}
function getSize (code) {
return (code.length / 1024).toFixed(2) + 'kb'
}