-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const rollup = require('rollup').rollup | ||
const buble = require('rollup-plugin-buble') | ||
const uglify = require('uglify-js') | ||
const packageData = require('../package.json') | ||
const mkdirp = require('mkdirp') | ||
const { version, author, name } = packageData | ||
// remove the email at the end | ||
const authorName = author.replace(/\s+<.*/, '') | ||
const moduleName = 'Vuefire' | ||
|
||
// Make sure dist dir exists | ||
mkdirp('dist') | ||
|
||
const { | ||
logError, | ||
write, | ||
} = require('./utils') | ||
|
||
const banner = | ||
'/*!\n' + | ||
` * ${name} v${version}\n` + | ||
` * (c) ${new Date().getFullYear()} ${authorName}\n` + | ||
' * Released under the MIT License.\n' + | ||
' */' | ||
|
||
const bundleOptions = { | ||
banner, | ||
exports: 'named', | ||
format: 'umd', | ||
name: moduleName, | ||
} | ||
|
||
function createBundle ({ name, format }) { | ||
rollup({ | ||
input: 'src/index.js', | ||
plugins: [ | ||
buble({ | ||
objectAssign: 'Object.assign', | ||
}), | ||
], | ||
}).then(function (bundle) { | ||
const options = Object.assign({}, bundleOptions) | ||
if (format) options.format = format | ||
return bundle.generate(options) | ||
}).then(function ({ code }) { | ||
if (/min$/.test(name)) { | ||
const minified = uglify.minify(code, { | ||
output: { | ||
preamble: banner, | ||
ascii_only: true, | ||
}, | ||
}).code | ||
return write(`dist/${name}.js`, minified) | ||
} else { | ||
return write(`dist/${name}.js`, code) | ||
} | ||
}).catch(logError) | ||
} | ||
|
||
// Browser bundle (can be used with script) | ||
createBundle({ | ||
name, | ||
}) | ||
|
||
// Commonjs bundle (preserves process.env.NODE_ENV) so | ||
// the user can replace it in dev and prod mode | ||
createBundle({ | ||
name: `${name}.esm`, | ||
format: 'es', | ||
}) | ||
|
||
createBundle({ | ||
name: `${name}.common`, | ||
format: 'cjs', | ||
}) | ||
|
||
// Minified version for browser | ||
createBundle({ | ||
name: `${name}.min`, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const write = require('./write.js') | ||
const { logError } = require('./log.js') | ||
|
||
module.exports = { | ||
write, | ||
logError, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function logError (e) { | ||
console.log(e) | ||
} | ||
|
||
function blue (str) { | ||
return `\x1b[1m\x1b[34m${str}\x1b[39m\x1b[22m` | ||
} | ||
|
||
function green (str) { | ||
return `\x1b[1m\x1b[32m${str}\x1b[39m\x1b[22m` | ||
} | ||
|
||
function red (str) { | ||
return `\x1b[1m\x1b[31m${str}\x1b[39m\x1b[22m` | ||
} | ||
|
||
function yellow (str) { | ||
return `\x1b[1m\x1b[33m${str}\x1b[39m\x1b[22m` | ||
} | ||
|
||
module.exports = { | ||
blue, | ||
green, | ||
red, | ||
yellow, | ||
logError, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const fs = require('fs') | ||
|
||
const { blue } = require('./log.js') | ||
|
||
function write (dest, code) { | ||
return new Promise(function (resolve, reject) { | ||
fs.writeFile(dest, code, function (err) { | ||
if (err) return reject(err) | ||
console.log(blue(dest) + ' ' + getSize(code)) | ||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
function getSize (code) { | ||
return (code.length / 1024).toFixed(2) + 'kb' | ||
} | ||
|
||
module.exports = write |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters