-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.rollup.js
131 lines (127 loc) · 3.74 KB
/
core.rollup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//rollup
let rollup = require('rollup');
//rollup plugins
let nodeResolve = require('rollup-plugin-node-resolve');
let commonjs = require('rollup-plugin-commonjs');
let globals = require('rollup-plugin-node-globals');
let replace = require('rollup-plugin-replace');
let strip = require('rollup-plugin-strip');
let buble = require('rollup-plugin-buble');
let uglify = require('rollup-plugin-uglify');
let rollupJson = require('rollup-plugin-json');
let filesize = require('rollup-plugin-filesize');
let eslint = require('rollup-plugin-eslint');
//vue.js related
let vue = require('rollup-plugin-vue2');
//css related
let postcss = require('rollup-plugin-postcss-export');
let postcssImport = require('postcss-import');
let postcssCenter = require('postcss-center');
let postcssSass = require('precss');
let postcssNext = require('postcss-cssnext');
let postcssRemoveDuplicates = require('postcss-deduplicate');
let postcssMinifySelectors = require('postcss-minify-selectors');
let postcssDiscardDuplicates = require('postcss-discard-duplicates');
let perfectionist = require('perfectionist');
let postcssClean = require('postcss-clean');
let postCss_plugins = [
postcssImport,
postcssCenter,
postcssSass,
postcssMinifySelectors,
postcssRemoveDuplicates,
postcssDiscardDuplicates,
postcssNext({
browsers: ['> 5%', 'ie >= 9']
})
];
let general = {
sourceMap: true
}
if (process.env.NODE_ENV === 'production') {
general.sourceMap = false;
postCss_plugins.push(postcssClean({
aggressiveMerging: true
}));
} else {
postCss_plugins.push(perfectionist);
}
// used to track the cache for subsequent bundles
let cache = null;
let rollitup = function(pkg, done, donePostCss) {
rollup.rollup({
// The bundle's starting point. This file will be
// included, along with the minimum necessary code
// from its dependencies
entry: pkg.entry,
// If you have a bundle you want to re-use (e.g., when using a watcher to rebuild as files change),
// you can tell rollup use a previous bundle as its starting point.
// This is entirely optional!
cache: cache,
plugins: [
rollupJson(),
(process.env.NODE_ENV === 'production' && strip({
debugger: true,
functions: ['console.*', 'assert.*', 'debug', 'alert'],
sourceMap: false
})),
vue(),
postcss({
plugins: postCss_plugins,
parse: true,
extensions: ['.css','.sss','.less', '.scss'],
output: pkg.dest.replace('.js', '.css')
}, donePostCss),
(process.env.NODE_ENV !== 'production' && eslint()),
buble({
transforms: {
arrow: true,
modules: true,
classes: true,
dangerousForOf: true
}
}),
nodeResolve({
jsnext: true,
main: true,
browser: true
}),
commonjs({
exclude: 'node_modules/process-es6/**',
include: []
}),
globals(),
replace({
__LANGUAGE__: pkg.language,
__VERSION__: JSON.stringify(pkg.version),
'process.env.VUE_ENV': JSON.stringify('browser'),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
(process.env.NODE_ENV === 'production' && uglify()),
filesize({
render: function(o, s, g) {
var date = new Date;
var time = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
return '[' + time + '] '+'BUBLE BUNDLE SIZE '+ "'" + '\x1b[32m' + s + '\x1b[0m' + "'";
}
})
]
}).then(function(bundle) {
// Cache our bundle for later use (optional)
cache = bundle;
// rollup generate bundle
bundle.write({
banner: '/*! ' + pkg.name + ' - v' + pkg.version + ' */',
moduleName: pkg.name,
useStrict: pkg['strict-mode'],
format: pkg.format || "iife",
dest: pkg.dest,
sourceMap: general.sourceMap,
sourceMapFile: pkg.dest + '.map'
});
if (typeof(done) == 'function') {
done();
}
});
}
module.exports = rollitup;