Skip to content

Commit cae6fdf

Browse files
committed
chore: Add i18n & icons for UMD version
1 parent 4fc4e45 commit cae6fdf

File tree

4 files changed

+126
-47
lines changed

4 files changed

+126
-47
lines changed

build/build.utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,14 @@ module.exports.readFile = function (file) {
4040
module.exports.logError = function (err) {
4141
console.error('[Error]'.red, err)
4242
}
43+
44+
module.exports.rollupQuasarUMD = function (config = {}) {
45+
return {
46+
name: 'quasar-umd',
47+
transform (code, id) {
48+
return {
49+
code: `Quasar.${config.type}.set(${code.replace('export default ', '')})`
50+
}
51+
}
52+
}
53+
}

build/script.build.javascript.js

Lines changed: 98 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
process.env.BABEL_ENV = 'production'
22

33
const
4-
54
path = require('path'),
6-
5+
fs = require('fs'),
76
rollup = require('rollup'),
87
uglify = require('uglify-es'),
98
buble = require('rollup-plugin-buble'),
@@ -18,44 +17,98 @@ const
1817
htmlMinifier: {collapseBooleanAttributes: false}
1918
}
2019

21-
function resolve (_path) {
22-
return path.resolve(__dirname, '..', _path)
23-
}
24-
25-
build([
20+
const builds = [
21+
{
22+
rollup: {
23+
input: resolve(`src/index.esm.js`),
24+
output: resolve(`dist/quasar.${buildConf.themeToken}.esm.js`),
25+
format: 'es'
26+
},
27+
meta: { buildUnminified: true }
28+
},
2629
{
27-
input: resolve(`src/index.esm.js`),
28-
output: resolve(`dist/quasar.${buildConf.themeToken}.esm.js`),
29-
format: 'es'
30+
rollup: {
31+
input: resolve('src/ie-compat/ie.js'),
32+
output: resolve('dist/quasar.ie.polyfills.js'),
33+
format: 'es'
34+
},
35+
meta: { buildUnminified: true }
3036
},
3137
{
32-
input: resolve('src/ie-compat/ie.js'),
33-
output: resolve('dist/quasar.ie.polyfills.js'),
34-
format: 'umd'
38+
rollup: {
39+
input: resolve('src/ie-compat/ie.js'),
40+
output: resolve('dist/umd/quasar.ie.polyfills.umd.js'),
41+
format: 'umd'
42+
},
43+
meta: { buildMinified: true }
3544
},
3645
{
37-
input: resolve(`src/index.umd.js`),
38-
output: resolve(`dist/quasar.${buildConf.themeToken}.umd.js`),
39-
format: 'umd'
46+
rollup: {
47+
input: resolve(`src/index.umd.js`),
48+
output: resolve(`dist/umd/quasar.${buildConf.themeToken}.umd.js`),
49+
format: 'umd'
50+
},
51+
meta: {
52+
buildUnminified: true,
53+
buildMinified: true
54+
}
4055
}
41-
])
56+
]
57+
58+
addAssets(builds, 'i18n')
59+
addAssets(builds, 'icons')
60+
61+
build(builds)
62+
63+
/**
64+
* Helpers
65+
*/
66+
67+
function resolve (_path) {
68+
return path.resolve(__dirname, '..', _path)
69+
}
70+
71+
function camel (str) {
72+
return str.charAt(0).toUpperCase() + str.substr(1)
73+
}
74+
75+
function addAssets (builds, type) {
76+
const
77+
files = fs.readdirSync(resolve(type)),
78+
plugins = [ buble() ],
79+
camelType = camel(type)
80+
81+
files.forEach(file => {
82+
const name = file.replace(/-([a-z])/g, g => g[1].toUpperCase())
83+
builds.push({
84+
rollup: {
85+
input: resolve(`${type}/${file}`),
86+
output: addExtension(resolve(`dist/umd/${type}.${file}`), 'umd'),
87+
name: `Quasar${camelType}${camel(name)}`,
88+
format: 'umd',
89+
plugins
90+
},
91+
meta: {
92+
buildMinified: true
93+
}
94+
})
95+
})
96+
}
4297

4398
function processEntries (entries) {
4499
const builds = []
45100

46101
entries.forEach(entry => {
47-
if (entry.output.indexOf(buildConf.themeToken) === -1) {
102+
if (entry.rollup.output.indexOf(buildConf.themeToken) === -1) {
48103
builds.push(entry)
49104
return
50105
}
51106

52107
buildConf.themes.forEach(theme => {
53-
builds.push({
54-
input: entry.input,
55-
output: entry.output.replace(buildConf.themeToken, theme),
56-
format: entry.format,
57-
meta: { theme }
58-
})
108+
const clone = JSON.parse(JSON.stringify(entry))
109+
clone.rollup.output = entry.rollup.output.replace(buildConf.themeToken, theme)
110+
clone.meta.theme = theme
111+
builds.push(clone)
59112
})
60113
})
61114

@@ -73,7 +126,7 @@ function genConfig (opts) {
73126
? opts.meta.theme
74127
: null
75128

76-
const plugins = [
129+
const plugins = opts.meta.plugins || [
77130
nodeResolve({
78131
extensions: theme
79132
? [`.${theme}.js`, '.js', `.${theme}.vue`, '.vue']
@@ -93,35 +146,40 @@ function genConfig (opts) {
93146
)
94147
}
95148

96-
Object.assign(opts, {
149+
Object.assign(opts.rollup, {
97150
banner: buildConf.banner,
98-
name: 'Quasar',
151+
name: opts.rollup.name || 'Quasar',
99152
plugins
100153
})
101154

102-
delete opts.meta
103-
104155
if (opts.format === 'umd') {
105-
opts.globals = {vue: 'Vue'}
106-
opts.external = ['vue']
156+
opts.rollup.globals = opts.rollup.globals || {}
157+
opts.rollup.globals.vue = 'Vue'
158+
159+
opts.rollup.external = opts.rollup.external || []
160+
opts.rollup.external.push('vue')
107161
}
108162

109163
return opts
110164
}
111165

112-
function addMinExtension (filename) {
166+
function addExtension (filename, ext = 'min') {
113167
const insertionPoint = filename.lastIndexOf('.')
114-
return `${filename.slice(0, insertionPoint)}.min${filename.slice(insertionPoint)}`
168+
return `${filename.slice(0, insertionPoint)}.${ext}${filename.slice(insertionPoint)}`
115169
}
116170

117171
function buildEntry (config) {
118172
return rollup
119-
.rollup(config)
120-
.then(bundle => bundle.generate(config))
121-
.then(({ code }) => buildUtils.writeFile(config.output, code))
173+
.rollup(config.rollup)
174+
.then(bundle => bundle.generate(config.rollup))
175+
.then(({ code }) => {
176+
return config.meta.buildUnminified
177+
? buildUtils.writeFile(config.rollup.output, code)
178+
: code
179+
})
122180
.then(code => {
123-
if (config.format !== 'umd') {
124-
return new Promise((resolve) => resolve(code))
181+
if (!config.meta.buildMinified) {
182+
return code
125183
}
126184

127185
const minified = uglify.minify(code, {
@@ -135,8 +193,8 @@ function buildEntry (config) {
135193
}
136194

137195
return buildUtils.writeFile(
138-
addMinExtension(config.output),
139-
(config.banner ? config.banner + '\n' : '') + minified.code,
196+
addExtension(config.rollup.output),
197+
(config.banner ? config.rollup.banner + '\n' : '') + minified.code,
140198
true
141199
)
142200
})

build/script.build.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
2-
var
1+
const
2+
fs = require('fs'),
33
path = require('path'),
44
shell = require('shelljs'),
55
type = process.argv[2]
@@ -13,13 +13,23 @@ var
1313

1414
require('colors')
1515

16+
function createFolder (folder) {
17+
const dir = path.join(__dirname, '..', folder)
18+
if (!fs.existsSync(dir)) {
19+
fs.mkdirSync(dir)
20+
}
21+
}
22+
1623
if (!type) {
1724
require('./script.clean.js')
1825
shell.mkdir('-p', path.join(__dirname, '../dist/'))
1926
}
2027

2128
console.log(' Building Quasar...\n')
2229

30+
createFolder('dist')
31+
createFolder('dist/umd')
32+
2333
if (!type || type === 'js') {
2434
require('./script.build.javascript')
2535
}

build/script.build.stylus.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ function generateTheme (theme) {
4242
return new Promise((resolve, reject) => resolve(code.css))
4343
})
4444
.then(code => Promise.all([
45-
generateStandalone(theme, code),
46-
generateStandalone(theme, rtlcss.process(code), '.rtl')
45+
generateUMD(theme, code),
46+
generateUMD(theme, rtlcss.process(code), '.rtl')
4747
]))
4848
}
4949

50-
function generateStandalone (theme, code, ext = '') {
51-
return buildUtils.writeFile(`dist/quasar.${theme}${ext}.css`, code, true)
50+
function generateUMD (theme, code, ext = '') {
51+
return buildUtils.writeFile(`dist/umd/quasar.${theme}${ext}.css`, code, true)
5252
.then(code => cssnano.process(code))
53-
.then(code => buildUtils.writeFile(`dist/quasar.${theme}${ext}.min.css`, code.css, true))
53+
.then(code => buildUtils.writeFile(`dist/umd/quasar.${theme}${ext}.min.css`, code.css, true))
5454
}
5555

5656
function prepareStylus (src) {

0 commit comments

Comments
 (0)