Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 17, 2016
1 parent cf770fe commit 84ff452
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 49 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"es2015-rollup"
]
}

39 changes: 24 additions & 15 deletions dist/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
'use strict';

function cube ( x ) {
return x * x * x;
}

function a(y){
return cube(y) + 55
}

console.log( cube( 5 ) ); // 125
console.log( a( 5 ) ); // 125


// var v = new validator();
!function(global, factory) {
"object" === typeof exports && "undefined" !== typeof module ? factory() : "function" === typeof define && define.amd ? define(factory) : factory();
}(this, function() {
"use strict";
function cube(x) {
return x * x * x;
}
function a(y) {
return cube(y) + 55;
}
var ab = {
test: function() {
return "2";
}
}, foos = {
"catch": function() {}
};
console.log(foos);
console.log(cube(5));
// 125
console.log(a(5));
// 125
console.log(ab.test());
});
82 changes: 82 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const gulp = require('gulp');
const rollup = require('gulp-rollup')
const uglify = require('gulp-uglify');
const babel = require('rollup-plugin-babel');
const fs = require('fs');
// var rollup = require('rollup').rollup;
// var commonjs = require('rollup-plugin-commonjs');
// var nodeResolve = require('rollup-plugin-node-resolve');

gulp.task('default', () => {
gulp.src('src/main.js')
.pipe(rollup({
// any option supported by rollup can be set here, including sourceMap
// sourceMap: true
format: 'umd',
plugins:[
babel({
exclude: 'node_modules/**/*',
// //externalHelpers 不包含到我打包的JS里面去
// externalHelpers: true,
// http://babeljs.io/docs/plugins/transform-es3-property-literals/
// 暂时好像搞不定
// "plugins": ["transform-es3-property-literals"]
})
]
}))
// babel 一些奇怪的转化方式,需要通过 uglify 再转换一下
.pipe(uglify({
mangle:false,
preserveComments: 'all',
compress:{
sequences : false, // join consecutive statemets with the “comma operator”
properties : false, // optimize property access: a["foo"] → a.foo
// dead_code : true, // discard unreachable code
// drop_debugger : true, // discard “debugger” statements
// unsafe : false, // some unsafe optimizations (see below)
// conditionals : true, // optimize if-s and conditional expressions
comparisons : false, // optimize comparisons
// evaluate : true, // evaluate constant expressions
// booleans : true, // optimize boolean expressions
// loops : true, // optimize loops
unused : true, // drop unused variables/functions
// hoist_funs : true, // hoist function declarations
// hoist_vars : false, // hoist variable declarations
if_return : false, // optimize if-s followed by return/continue
join_vars : true, // join var declarations
// cascade : true, // try to cascade `right` into `left` in sequences
// side_effects : true, // drop side-effect-free statements
// warnings : true, // warn about potentially dangerous optimizations/code
// global_defs : {} // global definitions
},
output: {
beautify: true
},
banner:"/* eew */"
}))
.pipe(gulp.dest('dist'));
});


// gulp.task('default', function () {
// return rollup({
// entry: 'src/main.js',
// plugins: [
// nodeResolve({ jsnext: true }),
// commonjs()
// ]
// }).then(function (bundle) {
// // 输出 bundle + sourcemap
// var result = bundle.generate({
// // output format - 'amd', 'cjs', 'es6', 'iife', 'umd'
// format: 'umd'
// });

// fs.writeFileSync( 'bundle.js', result.code );

// bundle.write({
// format: 'cjs',
// dest: 'dist/main.js'
// });
// });
// });
28 changes: 0 additions & 28 deletions gulpfile.js

This file was deleted.

20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
"name": "rollup-demo",
"version": "1.0.0",
"description": "rollup demo",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/jaywcjlove/rollup-demo"
},
"main": "src/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"author": "kenny wang <[email protected]> (http://JSLite.io)",
"license": "MIT",
"devDependencies": {
"gulp": "^3.9.1"
},
"dependencies": {
"babel-preset-es2015-rollup": "^1.1.1",
"gulp": "^3.9.1",
"rollup": "^0.25.4",
"rollup-plugin-commonjs": "^2.2.1",
"rollup-plugin-node-resolve": "^1.4.0"
"gulp-rollup": "^1.7.0",
"gulp-uglify": "^1.5.3",
"rollup-plugin-babel": "^2.4.0"
}
}
19 changes: 19 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
// import { validator } from 'validator.tool';
import { cube } from './maths.js';
import { a } from './a.js';

var ab = {
test(){
return "2"
}
}

// var foo = {
// get bar() {
// return "bar";
// }
// };

var foos = {
catch: function () {}
};

console.log(foos );
console.log( cube( 5 ) ); // 125
console.log( a( 5 ) ); // 125
console.log( ab.test() ); // 125


// var v = new validator();

0 comments on commit 84ff452

Please sign in to comment.