Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 3d5d64f

Browse files
committed
export cjs module
1 parent 53c51a5 commit 3d5d64f

File tree

5 files changed

+121
-5
lines changed

5 files changed

+121
-5
lines changed

config/banner.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
3+
let pack = require('../package.json')
4+
5+
const VERSION = process.env.VERSION || pack.version
6+
const YEAR = new Date().getFullYear();
7+
8+
const BANNER = `/*!
9+
* ${pack.name} v${VERSION}
10+
* (c) ${YEAR} ${pack.author.name}
11+
* Release under the ${pack.license} License.
12+
*/`;
13+
14+
15+
module.exports = BANNER;

config/build.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"use strict";
2+
3+
const babel = require('rollup-plugin-babel');
4+
const rollup = require('rollup');
5+
const replace = require('rollup-plugin-replace');
6+
const zlib = require('zlib');
7+
const fs = require('fs');
8+
const pack = require('../package.json');
9+
const banner = require('./banner');
10+
11+
// update main file
12+
let main = fs
13+
.readFileSync('src/index.js', 'utf-8')
14+
.replace(/plugin\.version = '[\d\.]+'/, `plugin.version = '${pack.version}'`);
15+
16+
fs.writeFileSync('src/index.js', main);
17+
18+
// CommonJS build.
19+
// this is used as the "main" field in package.json
20+
// and used by bundlers like Webpack and Browserify.
21+
rollup.rollup({
22+
entry: 'src/index.js',
23+
plugins: [
24+
babel({
25+
presets: ['es2015-rollup']
26+
})
27+
]
28+
})
29+
.then(function (bundle) {
30+
return write('dist/' + pack.name + '.common.js', bundle.generate({
31+
format: 'cjs',
32+
banner: banner
33+
}).code)
34+
})
35+
.catch(logError)
36+
37+
function write(dest, code) {
38+
return new Promise(function (resolve, reject) {
39+
fs.writeFile(dest, code, function (err) {
40+
if (err) return reject(err)
41+
console.log(blue(dest) + ' ' + getSize(code))
42+
resolve()
43+
})
44+
})
45+
}
46+
47+
function getSize(code) {
48+
return (code.length / 1024).toFixed(2) + 'kb'
49+
}
50+
51+
function logError(e) {
52+
console.log(e)
53+
}
54+
55+
function blue(str) {
56+
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
57+
}

dist/rollup-plugin-vue.common.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*!
2+
* rollup-plugin-vue v1.0.0
3+
* (c) 2016 undefined
4+
* Release under the MIT License.
5+
*/
6+
'use strict';
7+
8+
var rollupPluginutils = require('rollup-pluginutils');
9+
10+
var _require = require('vueify');
11+
12+
var compiler = _require.compiler;
13+
14+
function plugin() {
15+
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
16+
17+
var filter = rollupPluginutils.createFilter(options['include'], options['exclude']);
18+
19+
return {
20+
transform: function transform(code, id) {
21+
if (!filter(id)) return;
22+
23+
return new Promise(function (resolve, reject) {
24+
compiler['compile'](code, id, function (error, compiled) {
25+
if (error) reject(compiled);
26+
27+
resolve(compiled);
28+
});
29+
});
30+
}
31+
};
32+
}
33+
34+
plugin.version = '1.0.0';
35+
36+
module.exports = plugin;

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"name": "rollup-plugin-vue",
33
"version": "1.0.0",
44
"description": "Roll .vue files",
5-
"main": "index.js",
6-
"scripts": {},
5+
"main": "dist/rollup-plugin-vue.common.js",
6+
"scripts": {
7+
"build": "node --harmony config/build.js"
8+
},
79
"repository": {
810
"type": "git",
911
"url": "git+https://github.com/znck/rollup-plugin-vue.git"
@@ -21,5 +23,11 @@
2123
"dependencies": {
2224
"rollup-pluginutils": "latest",
2325
"vueify": "latest"
26+
},
27+
"devDependencies": {
28+
"babel-preset-es2015-rollup": "^1.1.1",
29+
"rollup": "^0.25.1",
30+
"rollup-plugin-babel": "^2.3.9",
31+
"rollup-plugin-replace": "^1.1.0"
2432
}
2533
}

index.js renamed to src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {createFilter} from 'rollup-pluginutils';
22
const {compiler} = require('vueify');
33

4-
export default vue;
4+
export default plugin;
55

6-
function vue(options = {}) {
6+
function plugin(options = {}) {
77
let filter = createFilter(options['include'], options['exclude']);
88

99
return {
@@ -23,5 +23,5 @@ function vue(options = {}) {
2323
};
2424
}
2525

26-
vue.version = '1.0.0';
26+
plugin.version = '1.0.0';
2727

0 commit comments

Comments
 (0)