Commit ce070688 authored by wildfirecode's avatar wildfirecode

1

parent 24f46948
# dbgame-build
# todo
- 直接在指定项目下执行duibabuild
\ No newline at end of file
var opn = require('opn');
var path = require('path');
var webpack = require('webpack');
var devConfig = require('./webpack.dev.conf');
const WebpackDevServer = require('webpack-dev-server');
// const apiMocker = require('webpack-api-mocker');
var serverStart = opts => {
let webpackConfig = devConfig(opts);
// 遍历每个entry,加入dev-server client
Object.keys(webpackConfig.entry).forEach(function (name) {
let _devServer = `webpack-dev-server/client?http://localhost:${
opts.devPort
}`;
webpackConfig.entry[name] = [_devServer].concat(webpackConfig.entry[name]);
});
var compiler = webpack(webpackConfig);
const devServerOptions = {
host: '0.0.0.0',
watchContentBase: true,
watchOptions: opts.devServerWatchOptions,
contentBase: `.`,
proxy: opts.proxy,
after(app) {
// 自动打开浏览器
if (opts.BUILD_SKIN) {
opn(
`http://localhost:${opts.devPort}/${opts.BUILD_SKIN}/index.html`
);
}
}
};
WebpackDevServer.addDevServerEntrypoints(webpackConfig, devServerOptions);
const devServer = new WebpackDevServer(compiler, devServerOptions);
devServer.listen(opts.devPort, '0.0.0.0', () => {
console.log(`Starting server ...`);
});
};
module.exports = {
close: () => { },
start: opts => {
serverStart(opts);
}
};
\ No newline at end of file
var webpack = require('webpack');
var getDevConfig = require('./webpack.dev');
const WebpackDevServer = require('webpack-dev-server');
var serverStart = proj => {
const devConfig = getDevConfig(proj);
// 遍历每个entry,加入dev-server client
Object.keys(devConfig.entry).forEach(function(name) {
let _devServer = `webpack-dev-server/client?http://localhost:8080`;
devConfig.entry[name] = [_devServer].concat(devConfig.entry[name]);
});
console.log(devConfig.entry)
var compiler = webpack(devConfig);
const devServerOptions = {
host: '0.0.0.0',
watchContentBase: true,
watchOptions:{
ignored:[
'src/**/*.js',
'**/*.md',
'bin-release',
]
},
contentBase: `./${proj}`,
proxy: {
'/ngapi/*': 'http://localhost:3000',
'/plugin/*': 'http://localhost:3000',
'/ngame/*': 'http://localhost:3000',
'/activityCommon/*': 'http://localhost:3000',
'/ctool/*': 'http://localhost:3000',
'/activityVist/*': 'http://localhost:3000',
'/collectGoods/*': 'http://localhost:3000',
'/activityPlugDrawInfo/*': 'http://localhost:3000',
'/collectRule/*': 'http://localhost:3000',
'/hdtool/*': 'http://localhost:3000',
'/activityPlugin/*': 'http://localhost:3000',
'/summer/*': 'http://localhost:3000'
},
};
WebpackDevServer.addDevServerEntrypoints(devConfig, devServerOptions);
const devServer = new WebpackDevServer(compiler, devServerOptions);
devServer.listen(8080, '0.0.0.0', () => {
console.log(`Starting server ...`);
});
};
module.exports = {
close: () => { },
start: proj => {
serverStart(proj);
}
};
\ No newline at end of file
const path = require('path');
module.exports = proj => {
module.exports = opts => {
const result = {
entry: {app:`./${proj}/src/Main.ts`},
entry: {
app: `./${opts.BUILD_SKIN}/src/Main.ts`
},
module: {
rules: [
{
......
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const webpack = require('webpack');
var merge = require('webpack-merge');
var baseConfig = require('./webpack.base.conf');
const MockWebpackPlugin = require('mock-webpack-plugin');
const mockConfig = require('./mock/config.js');
module.exports = proj => {
const commonConfig = common(proj);
const result = merge(commonConfig, {
let config = opts => {
let baseWebpackConfig = baseConfig(opts);
return merge(baseWebpackConfig, {
mode: 'development',
devtool: 'eval-source-map',
// // cheap-module-eval-source-map is faster for development
// devtool: '#cheap-module-eval-source-map',
plugins: [
new MockWebpackPlugin({
config: mockConfig,
......@@ -15,5 +19,6 @@ module.exports = proj => {
})
]
});
return result;
}
\ No newline at end of file
};
module.exports = config;
#!/usr/bin/env node
var argv = require('yargs')
.option('project', {
alias: 'proj',
demand: true,
describe: '项目名称',
type: 'string'
})
// .option('i', {
// alias: 'input',
// demand: true,
// describe: '输入路径',
// type: 'string'
// })
.usage('Usage: duibabuild -proj kickball-egret')
.example('duibabuild')
.help('h')
.alias('h', 'help')
.argv;
const server = require('./build/server');
server.start(argv.project);
const devServer = require('./build/dev-server');
// const build = require('./build/build');
// const backup = require('./util/backup');
// const copy = require('./util/copy');
class DuibaGameBuild {
constructor(config) {
let defaults = {
devPort: 8081,
devServerWatchOptions: {
ignored: [
'src/**/*.js',
'**/*.md',
'bin-release',
]
},
proxy: {
'/ngapi/*': 'http://localhost:3000',
'/plugin/*': 'http://localhost:3000',
'/ngame/*': 'http://localhost:3000',
'/activityCommon/*': 'http://localhost:3000',
'/ctool/*': 'http://localhost:3000',
'/activityVist/*': 'http://localhost:3000',
'/collectGoods/*': 'http://localhost:3000',
'/activityPlugDrawInfo/*': 'http://localhost:3000',
'/collectRule/*': 'http://localhost:3000',
'/hdtool/*': 'http://localhost:3000',
'/activityPlugin/*': 'http://localhost:3000',
'/summer/*': 'http://localhost:3000'
}
};
this.opts = Object.assign({}, defaults, config);
global.buildOptions = this.opts;
}
/**
* 本地开发服务
* @param {*} skin 皮肤名称
*/
dev(skin) {
process.env.NODE_ENV = '"development"';
this.slicePath(skin);
devServer.start(this.opts);
}
/**
* 构建 daily库 dui88环境
* @param {*} skin 皮肤名称
*/
build(skin) {
this.opts.sourceMap = false;
this.opts.daily = true;
this.buildBase(skin);
}
/**
* 构建 duiba库 生产环境
* @param {*} skin 皮肤名称
*/
buildProd(skin) {
this.opts.daily = false;
this.buildBase(skin);
}
/**
* 构建 统一入口
* @param {*} skin 皮肤名称
*/
buildBase(skin) {
process.env.NODE_ENV = '"production"';
this.slicePath(skin);
build(this.opts);
}
/**
* 备份 把skins/下的所有文件复制到backup/下
*/
backup() {
backup(this.opts.skins, this.opts.backup);
}
/**
* 创建模板
* @param {*} skin 皮肤名称
* @param {*} temp 模板名称
*/
copy(skin, temp) {
copy(this.opts, skin, temp);
}
/**
* 路径处理 支持 demo 和 path/demo/demo 多种参数格式
* @param {*} skin
*/
slicePath(skin) {
if (!skin) return false;
if (skin.includes('/')) {
// 包含路径
this.opts.BUILD_PATH = skin.split('/').pop();
}
this.opts.BUILD_SKIN = skin;
}
}
module.exports = DuibaGameBuild;
{
"name": "duibabuild",
"bin": {
"duibabuild": "duibabuild.js"
},
"name": "duiba-game-build",
"main": "index.js",
"dependencies": {
"yargs": "^12.0.1",
"ts-loader": "^4.0.0",
"typescript": "^3.0.3",
"webpack": "^4.1.0",
......@@ -13,5 +10,5 @@
"webpack-merge": "^4.1.2",
"mock-webpack-plugin": "^2.0.0"
},
"version": "0.0.4"
"version": "0.0.1"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment