forked from NewDadaFE/vue-impression
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
121 lines (106 loc) · 3.13 KB
/
build.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
'use strict'
var path = require('path');
var fs = require('fs');
var webpack = require('webpack');
var buildConfig = {};
var pkg = require(path.join(__dirname, './package.json'));
var getConfig = function () {
var config = {
entry: {},
output: {
path: path.resolve(__dirname, 'dist/scripts/components/'),
filename: "[name].js"
},
resolve: {
extensions: ['', '.js', '.vue'],
},
resolveLoader: {
fallback: [path.join(__dirname, 'node_modules')],
root: path.join(__dirname, 'node_modules'),
},
module: {
loaders: [{
test: /\.vue$/,
loader: 'vue'
}, {
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
}, {
test: /\.json$/,
loader: 'json'
}, {
test: /\.(png|jpg|gif|svg)$/,
loader: 'url',
query: {
limit: 10000,
name: '[name].[ext]?[hash:7]'
}
}]
},
vue: {
loaders: {
js: 'babel'
}
},
eslint: {
formatter: require('eslint-friendly-formatter')
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin(),
],
};
return config;
};
var componentsDir = path.resolve(__dirname, './src/scripts/components/');
fs.readdir(componentsDir, function (err, files) {
if (err) {
throw err
}
files.filter(function (file) {
return file.endsWith('.vue') && fs.statSync(path.join(componentsDir, file)).isFile();
}).forEach(function (file) {
build(file);
});
});
var number = 0;
function build (name, _path) {
let _config = getConfig();
let _name = name.replace('.vue', '');
let file = `./src/scripts/components/${_name}`;
let _start = new Date().getTime();
_config.output.libraryTarget = 'umd';
_config.entry[_name] = path.resolve(__dirname, file);
_config.output.library = _name;
webpack(_config, function (err, stats) {
var jsonStats = stats.toJson();
var assets = jsonStats.assets[0];
var offset = Math.round((new Date().getTime() - _start) / 1000);
var index = ++number;
console.log(`[${index < 10 ? ('0' + index) : index}] `, addWhiteSpace(`${offset}s`, 10), addWhiteSpace('umd ' + _name, 25), `${(_name, assets.size / 1024).toFixed(2)}k`);
if (err) {
throw err;
}
});
}
function addWhiteSpace (str, number) {
if (str.length < number) {
var rs = str;
for (var i = 0; i < number - str.length; i++) {
rs += ' ';
}
return rs;
}
return str;
}