...
|
...
|
@@ -9,9 +9,15 @@ |
|
|
const fs = require('fs');
|
|
|
|
|
|
const gulp = require('gulp');
|
|
|
const gutil = require('gulp-util');
|
|
|
const postcss = require('gulp-postcss');
|
|
|
const sourcemaps = require('gulp-sourcemaps');
|
|
|
const cssnano = require('gulp-cssnano');
|
|
|
const webpack = require('webpack');
|
|
|
const webpackStream = require('webpack-stream');
|
|
|
const WebpackDevServer = require('webpack-dev-server');
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
const env = {
|
|
|
dev: Symbol('development'),
|
...
|
...
|
@@ -33,6 +39,8 @@ const dist = { |
|
|
font: `${rootdir}/assets/font`
|
|
|
};
|
|
|
|
|
|
const webpackConfig = require('./webpack.config.js');
|
|
|
|
|
|
/**
|
|
|
* postcss plugins for both dev and pro
|
|
|
* @parem et Symbol
|
...
|
...
|
@@ -105,6 +113,12 @@ const postcssPlugin = (et, module) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 返回发布目录对应模块的根目录
|
|
|
* @param module String 模块名
|
|
|
*/
|
|
|
const distModule = module => `./dist/${config.name}/${config.version}/${module}/`;
|
|
|
|
|
|
/**
|
|
|
* 模块下CSS编译
|
|
|
* @param module String 模块名
|
|
|
* @param et Symbol 环境
|
...
|
...
|
@@ -120,7 +134,7 @@ const compileForModule = (module, et) => { |
|
|
return gulp.src(`static/module/${module}/scss/index.css`)
|
|
|
.pipe(postcss(postcssPlugin(et, module)))
|
|
|
.pipe(cssnano())
|
|
|
.pipe(gulp.dest(`./dist/${config.name}/${config.version}/${module}/`));
|
|
|
.pipe(gulp.dest(distModule(module)));
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -169,6 +183,52 @@ gulp.task('postcss-watch', () => { |
|
|
});
|
|
|
});
|
|
|
|
|
|
// webpack-server
|
|
|
gulp.task('webpack', () => {
|
|
|
var proConfig = Object.assign({}, webpackConfig);
|
|
|
|
|
|
proConfig.plugins.push(
|
|
|
new webpack.optimize.DedupePlugin(),
|
|
|
new webpack.optimize.UglifyJsPlugin()
|
|
|
);
|
|
|
|
|
|
fs.readdir('static/module', (err, data) => {
|
|
|
if (err) {
|
|
|
console.log(err);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
for (let f of data) {
|
|
|
gulp.src(`static/module/${f}/js/index.js`)
|
|
|
.pipe(webpackStream(proConfig))
|
|
|
.pipe(gulp.dest(distModule(f)))
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
gulp.task('webpack-dev', () => {
|
|
|
new WebpackDevServer(webpack({
|
|
|
entry: './static/module',
|
|
|
output: {
|
|
|
filename: 'bundle.js'
|
|
|
}
|
|
|
}), {
|
|
|
// contentBase: 'http://localhost/',
|
|
|
// hot: true,
|
|
|
// filename: 'bundle.js',
|
|
|
// lazy: true
|
|
|
inline: true,
|
|
|
stats: {
|
|
|
clors: true
|
|
|
}
|
|
|
}).listen(8000, 'localhost', (err) => {
|
|
|
if (err) {
|
|
|
throw new gutil.PluginError('webpack-server', err);
|
|
|
}
|
|
|
gutil.log('[webpack-serve]', 'http://localhost:8000/');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// assets dest
|
|
|
gulp.task('assets', function() {
|
|
|
return gulp.src('static/assets/**')
|
...
|
...
|
|