Skip to content

Commit

Permalink
Merge pull request #212 from yugasun/fix/silent-nouse-bug
Browse files Browse the repository at this point in the history
Feat: add silent option for debug & update devDependencies
  • Loading branch information
hilongjw authored Jan 3, 2018
2 parents 2709b6e + 4b6a84a commit 10efc7f
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 347 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["es2015", { "modules": false }]
["env", { "modules": false }]
]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ new Vue({
| `throttleWait`|throttle wait|`200`|`Number`|
| `observer`|use IntersectionObserver|`false`|`Boolean`|
| `observerOptions`|IntersectionObserver options|{ rootMargin: '0px', threshold: 0.1 }|[IntersectionObserver](#intersectionobserver)|
| `silent`|do not print debug info|`true`|`Boolean`|

### Desired Listen Events

Expand Down Expand Up @@ -188,7 +189,7 @@ Vue.use(vueLazy, {

// optional
observerOptions: {
rootMargin: '0px',
rootMargin: '0px',
threshold: 0.1
}
})
Expand Down
103 changes: 57 additions & 46 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
var fs = require('fs')
var path = require('path')
var rollup = require('rollup')
var babel = require('rollup-plugin-babel')
var uglify = require('rollup-plugin-uglify')
var version = process.env.VERSION || require('./package.json').version

var banner =
'/*!\n' +
' * Vue-Lazyload.js v' + version + '\n' +
' * (c) ' + new Date().getFullYear() + ' Awe <[email protected]>\n' +
' * Released under the MIT License.\n' +
' */\n'

rollup.rollup({
entry: path.resolve(__dirname, 'src/index.js'),
plugins: [
babel(),
uglify()
]
})
.then(bundle => {
return write(path.resolve(__dirname, 'vue-lazyload.js'), rewriteVersion(bundle.generate({
format: 'umd',
moduleName: 'VueLazyload'
}).code))
})
.then(() => {
console.log('Vue-Lazyload.js v' + version + ' builded')
})
.catch(console.log)

function rewriteVersion (code) {
return code.replace('__VUE_LAZYLOAD_VERSION__', version)
const fs = require('fs')
const path = require('path')
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
const uglify = require('rollup-plugin-uglify')
const version = process.env.VERSION || require('./package.json').version

const banner =
'/*!\n' +
' * Vue-Lazyload.js v' + version + '\n' +
' * (c) ' + new Date().getFullYear() + ' Awe <[email protected]>\n' +
' * Released under the MIT License.\n' +
' */\n'
async function build() {
try {
const bundle = await rollup.rollup({
input: path.resolve(__dirname, 'src/index.js'),
plugins: [
babel({
exclude: 'node_modules/**',
plugins: ['external-helpers']
}),
uglify()
]
})

let { code } = await bundle.generate({
format: 'umd',
name: 'VueLazyload'
})

code = rewriteVersion(code)

await write(path.resolve(__dirname, 'vue-lazyload.js'), code)

console.log('Vue-Lazyload.js v' + version + ' builded')
} catch (e) {
console.log(e)
}
}

function rewriteVersion(code) {
return code.replace('__VUE_LAZYLOAD_VERSION__', version)
}

function getSize (code) {
return (code.length / 1024).toFixed(2) + 'kb'
function getSize(code) {
return (code.length / 1024).toFixed(2) + 'kb'
}

function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
function blue(str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}

function write (dest, code) {
return new Promise(function (resolve, reject) {
code = banner + code
fs.writeFile(dest, code, function (err) {
if (err) return reject(err)
console.log(blue(dest) + ' ' + getSize(code))
resolve()
function write(dest, code) {
return new Promise(function (resolve, reject) {
code = banner + code
fs.writeFile(dest, code, function (err) {
if (err) return reject(err)
console.log(blue(dest) + ' ' + getSize(code))
resolve()
})
})
})
}

build()
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"unpkg": "vue-lazyload.js",
"scripts": {
"start": "node build",
"compile": "babel --presets es2015 -d lib/ src/",
"test": "npm run compile && mocha --compilers js:babel-core/register"
"compile": "babel --presets env -d lib/ src/",
"test": "npm run compile && mocha --require babel-core/register"
},
"dependencies": {},
"repository": {
Expand All @@ -26,19 +26,18 @@
},
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-core": "^6.25.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-polyfill": "^6.13.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-es2015-rollup": "^1.2.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1",
"chai": "^4.1.0",
"mocha": "^3.4.2",
"rollup": "^0.35.10",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-uglify": "^1.0.1",
"vue": "^2.4.1"
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"mocha": "^4.0.1",
"rollup": "^0.52.1",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-uglify": "^2.0.1",
"vue": "^2.5.9"
}
}
Loading

0 comments on commit 10efc7f

Please sign in to comment.