From 06d6d420d49c8723f366f886078684cf2719aa43 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Fri, 26 Feb 2016 23:45:35 +0800 Subject: [PATCH] ... --- .gitignore | 1 + dist/main.js | 7 +++++++ gulpfile.js | 28 ++++++++++++++++++++++++++++ package.json | 17 +++++++++++++++++ src/main.js | 2 ++ src/maths.js | 7 +++++++ 6 files changed, 62 insertions(+) create mode 100644 .gitignore create mode 100644 dist/main.js create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/main.js create mode 100644 src/maths.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/dist/main.js b/dist/main.js new file mode 100644 index 0000000..d517d04 --- /dev/null +++ b/dist/main.js @@ -0,0 +1,7 @@ +'use strict'; + +function cube ( x ) { + return x * x * x; +} + +console.log( cube( 5 ) ); // 125 \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..1099b80 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,28 @@ +var gulp = require('gulp'); +var fs = require('fs'); +var rollup = require('rollup').rollup; +var commonjs = require('rollup-plugin-commonjs'); +var nodeResolve = require('rollup-plugin-node-resolve'); + +gulp.task('script', 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: 'cjs' + }); + + fs.writeFileSync( 'bundle.js', result.code ); + + bundle.write({ + format: 'cjs', + dest: 'dist/main.js' + }); + }); +}); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6a62bd4 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "rollup-demo", + "version": "1.0.0", + "description": "rollup demo", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "gulp": "^3.9.1", + "rollup": "^0.25.4", + "rollup-plugin-commonjs": "^2.2.1", + "rollup-plugin-node-resolve": "^1.4.0" + } +} diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..79c1141 --- /dev/null +++ b/src/main.js @@ -0,0 +1,2 @@ +import { cube } from './maths.js'; +console.log( cube( 5 ) ); // 125 \ No newline at end of file diff --git a/src/maths.js b/src/maths.js new file mode 100644 index 0000000..262d99e --- /dev/null +++ b/src/maths.js @@ -0,0 +1,7 @@ +export function square ( x ) { + return x * x; +} + +export function cube ( x ) { + return x * x * x; +} \ No newline at end of file