Authored by 徐炜

SPM改成webpack

@@ -23,4 +23,4 @@ sea-modules @@ -23,4 +23,4 @@ sea-modules
23 spm_modules 23 spm_modules
24 .cache 24 .cache
25 dist 25 dist
26 -web.log 26 +web.log
@@ -5,8 +5,8 @@ var fs = require('fs'); @@ -5,8 +5,8 @@ var fs = require('fs');
5 var exec = require('child_process').exec; 5 var exec = require('child_process').exec;
6 var jshint = require('gulp-jshint'); 6 var jshint = require('gulp-jshint');
7 var stylish = require('jshint-stylish'); 7 var stylish = require('jshint-stylish');
8 -  
9 - 8 +const webpack = require('webpack');
  9 +const webpackConfig = require('./webpack.config.js');
10 10
11 var ftpConfig = { 11 var ftpConfig = {
12 host: '218.94.75.58', 12 host: '218.94.75.58',
@@ -18,7 +18,6 @@ gulp.task('default', function() { @@ -18,7 +18,6 @@ gulp.task('default', function() {
18 18
19 }); 19 });
20 20
21 -  
22 //js代码验证 21 //js代码验证
23 gulp.task('lint', function() { 22 gulp.task('lint', function() {
24 return gulp.src(['src/*.js', 'src/**/*.js']) 23 return gulp.src(['src/*.js', 'src/**/*.js'])
@@ -27,24 +26,20 @@ gulp.task('lint', function() { @@ -27,24 +26,20 @@ gulp.task('lint', function() {
27 }); 26 });
28 27
29 28
30 -  
31 -//执行spm的build  
32 -gulp.task('spm', function(cb) {  
33 - exec('spm build --include standalone', function(err) {  
34 - if (err) return cb(err);  
35 - cb();  
36 - });  
37 -});  
38 -  
39 -gulp.task('js', ['spm'], function() {  
40 - console.log("压缩合并完成");  
41 -});  
42 -  
43 -  
44 //发布到CDN 29 //发布到CDN
45 -gulp.task('dist', ['spm'], function() { 30 +gulp.task('dist', ['build'], function() {
46 var ftpstream = ftp(ftpConfig); 31 var ftpstream = ftp(ftpConfig);
47 return gulp.src('dist/**') 32 return gulp.src('dist/**')
48 .pipe(ftpstream) 33 .pipe(ftpstream)
49 .pipe(gutil.noop()); 34 .pipe(gutil.noop());
  35 +});
  36 +
  37 +gulp.task('build', function(done) {
  38 + webpack(webpackConfig, function(err, stats) {
  39 + if (err) {
  40 + throw new gutil.PluginError('webpack', err);
  41 + }
  42 + gutil.log('[webpack compile]:', stats.endTime - stats.startTime, 'ms');
  43 + done();
  44 + });
50 }); 45 });
@@ -2,7 +2,12 @@ @@ -2,7 +2,12 @@
2 "name": "yas-jssdk", 2 "name": "yas-jssdk",
3 "version": "2.2.2", 3 "version": "2.2.2",
4 "description": "YOHO!采集系统的前端js的开发包", 4 "description": "YOHO!采集系统的前端js的开发包",
5 - "keywords": ["YOHO!", "Acquisition", "System", "JS-SDK"], 5 + "keywords": [
  6 + "YOHO!",
  7 + "Acquisition",
  8 + "System",
  9 + "JS-SDK"
  10 + ],
6 "homepage": "", 11 "homepage": "",
7 "author": "hbomb <qiqi.zhou@yoho.cn>", 12 "author": "hbomb <qiqi.zhou@yoho.cn>",
8 "repository": { 13 "repository": {
@@ -29,15 +34,27 @@ @@ -29,15 +34,27 @@
29 "buildArgs": "--include standalone" 34 "buildArgs": "--include standalone"
30 }, 35 },
31 "devDependencies": { 36 "devDependencies": {
  37 + "babel-core": "^6.21.0",
  38 + "babel-loader": "^6.2.10",
  39 + "babel-plugin-transform-runtime": "^6.15.0",
  40 + "babel-preset-es2015": "^6.18.0",
  41 + "babel-runtime": "^6.20.0",
  42 + "css-loader": "^0.26.1",
  43 + "expect.js": "^0.3.1",
32 "gulp": "^3.8.11", 44 "gulp": "^3.8.11",
33 "gulp-ftp": "^1.0.3", 45 "gulp-ftp": "^1.0.3",
34 "gulp-jshint": "^1.9.2", 46 "gulp-jshint": "^1.9.2",
35 "gulp-util": "^3.0.4", 47 "gulp-util": "^3.0.4",
36 "jshint-stylish": "^1.0.1", 48 "jshint-stylish": "^1.0.1",
37 - "spm": "3" 49 + "sinon": "^1.17.7",
  50 + "spm": "3",
  51 + "style-loader": "^0.13.1",
  52 + "webpack": "^1.14.0",
  53 + "webpack-uglify-parallel": "^0.1.3",
  54 + "yoho-json2": "^1.0.0"
38 }, 55 },
39 "scripts": { 56 "scripts": {
40 "test": "spm test", 57 "test": "spm test",
41 "build": "spm build" 58 "build": "spm build"
42 } 59 }
43 -}  
  60 +}
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 * @fileoverview YAS (YOHO! Acquisition System) YOHO!采集系统的前端js的开发包, 2 * @fileoverview YAS (YOHO! Acquisition System) YOHO!采集系统的前端js的开发包,
3 * 用于在网页端采集信息(应用信息,用户信息,用户行为信息,浏览器及其系统信息)。 3 * 用于在网页端采集信息(应用信息,用户信息,用户行为信息,浏览器及其系统信息)。
4 */ 4 */
5 -require('yoho.json2'); 5 +require('yoho-json2');
6 6
7 //工具库 7 //工具库
8 var util = require('./util'); 8 var util = require('./util');
@@ -24,6 +24,7 @@ var version = config.version; @@ -24,6 +24,7 @@ var version = config.version;
24 var yasPath = config.yaPath; 24 var yasPath = config.yaPath;
25 25
26 var yasDomain = config.yasDomain; 26 var yasDomain = config.yasDomain;
  27 +
27 //应用信息 28 //应用信息
28 var appInfo = { 29 var appInfo = {
29 h: document.domain, //host 30 h: document.domain, //host
  1 +'use strict';
  2 +
  3 +const webpack = require('webpack');
  4 +const path = require('path');
  5 +const _ = require('lodash');
  6 +const shelljs = require('shelljs');
  7 +const version = require('./package.json').version;
  8 +const UglifyJsParallelPlugin = require('webpack-uglify-parallel');
  9 +const os = require('os');
  10 +
  11 +module.exports = {
  12 + entry: {
  13 + 'yas': './yas.js'
  14 + },
  15 + output: {
  16 + path: path.join('dist', 'yas-jssdk', version), // absolute path
  17 + filename: '[name].js'
  18 + },
  19 + module: {
  20 + loaders: [{
  21 + test: /\.css$/, loader: "style-loader!css-loader"
  22 + }],
  23 + resolve: {
  24 + modulesDirectories: ['node_modules']
  25 + }
  26 + },
  27 + plugins: [
  28 + new webpack.optimize.OccurenceOrderPlugin(),
  29 + new UglifyJsParallelPlugin({
  30 + workers: os.cpus().length
  31 + })
  32 + ]
  33 +};