Files
wdp/task/task.js
T
2018-11-12 17:48:13 +08:00

51 lines
1.1 KiB
JavaScript

const path = require('path');
const fs = require('fs-extra');
const chalk = require('chalk');
const webpack = require('webpack');
const webpackDevServer = require('webpack-dev-server');
const util = require('./util');
const webpackConfig = require('./webpack.react');
let _paths = {};
let _configJson = {};
exports.init = (type, paths, command) => {
_paths = paths;
let tplPath = path.join(_paths.rootPath, util.tplTypePath(type));
fs.copy(tplPath, _paths.targetPath)
.then(() => {
console.log(chalk.bold.green('生成模板成功!'));
_configJson = util.configJson(_paths.targetPath);
if(_configJson.template == 'react') {
webpackConfig.run(command);
}
})
.catch(err => {
console.error(err);
console.error(chalk.bold.red('生成模板失败!'));
});
}
exports.dev = (paths, command) => {
_paths = paths;
if(_configJson.template == 'react') {
webpackConfig.run(paths, command);
}
}
exports.pack = (paths, command) => {
_paths = paths;
_configJson = util.configJson(_paths.targetPath);
if(_configJson.template == 'react') {
webpackConfig.run(paths, command);
}
}