UNPKG

app-lib-cli-plugin-server

Version:

app-lib-cli-plugin-server

184 lines (156 loc) 9.59 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else { var a = factory(); for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; } })(this, () => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 138: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { /** * 启动服务 * */ const es = __webpack_require__(495); const STATIC_FILE_DATA = __webpack_require__(177); module.exports = { start: (_opts) => { let { log, utils: { praseOpt, prase, bindArg }, OPTIONS, ARGUMENTS, CONSTANT: { TARGET }, STATIC: { jsonToFile } } = _opts; // 静态资源自动生成 jsonToFile(STATIC_FILE_DATA); const COMMOND_FN = { /** * * javascript 的执行 * */ es, }; // 动态处理支持的方法 const supportCommond = (() => { let commonds = []; for (let commond in COMMOND_FN) { commonds.push(commond); } return commonds; })(); // 初始化脚本 const init = (program, opt) => { const Option = opt.commander.Option; const PRASE = bindArg(prase, opt.commander.InvalidArgumentError); return program .argument(...ARGUMENTS.language(opt)) .addOption(new Option('-p, --port <number>', 'server port').argParser(PRASE.port).default(8080, '8080')) .addOption(new Option('-h, --host [string]', 'support ip address for visit')) .addOption(new Option('-m, --model [string]', 'support [example,test] ')) .addOption(OPTIONS.message(opt.commander)) .description('start language service') } /** * 执行脚本命令 * @param {*} opt * @returns // 非0 返回则为有异常 */ const start = async (opt) => { const options = praseOpt(opt); let { arg } = options; log.md('execute params:', options); let fn = COMMOND_FN[arg[0]]; if (!fn) throw log.me(`no exsit function ${arg[0]} to deal this commond,please develop this deal function`); return await fn(options, opt, _opts); } return { init, start, } } } /***/ }), /***/ 495: /***/ ((module) => { /************************************************************************************************** * es dev * * 依赖 * * html-webpack-plugin * * webpack * * webpack-cli * * webpack-dev-server * * ************************************************************************************************* */ // 具体执行可插件化 const start = async (args, opt, _opts) => { let { log, exec, nodeUtils: { getBin, getCanUsePort, isSysUsePort, readline }, utils: { optionsToArray, getStaticPath } } = _opts; let { option } = args; let port = 1 * option.port; // 文件配置路径 let configPath = getStaticPath(`${opt.commond}.${opt.options[0]}.webpack.${option.model ? (option.model + ".") : ''}config.js`); // TODO 追加自定义部分 let binPath = getBin('webpack-dev-server'); let isUse = await isSysUsePort(port); if (isUse) { let canUsePort = await getCanUsePort(port + 1); log.mwn(`[${port}] port is EADDRINUSE, use [${canUsePort}]?`); let isNewPort = await readline('yes/no', 'yes'); if (isNewPort === 'y' || isNewPort == 'yes') { port = canUsePort; } else { return log.mwn('npm init', `give up use port [${canUsePort}]`) } } option.port = port; exec(binPath, ['--config', configPath].concat(optionsToArray(option, ['target', 'model'])), { stdio: 'inherit' }) return 0; // 非0 返回则为有异常 } module.exports = start /***/ }), /***/ 177: /***/ ((module) => { "use strict"; module.exports = JSON.parse('[{"name":"server.es.webpack.config.js","content":"// 开发模式\\r\\nconst { log } = require(\'app-lib-log\');\\r\\nconst { resolve, getTemplate } = require(\'app-lib-node\')\\r\\nconst realPath = (p) => resolve(__dirname, process.cwd() + \'/\' + p);\\r\\nconst HTMLWebpackPlugin = require(\'html-webpack-plugin\');\\r\\nconst {autoRequire} = require(\\"app-lib-nobuild\\");\\r\\n\\r\\n\\r\\nconst config = {\\r\\n devtool: \'inline-source-map\',\\r\\n entry: {\\r\\n index: resolve(\'./src/index.js\'),\\r\\n },\\r\\n output: {\\r\\n path: resolve(\\"./\\"),\\r\\n filename: \'[name].js\',\\r\\n },\\r\\n module: {\\r\\n },\\r\\n plugins: [\\r\\n new HTMLWebpackPlugin({\\r\\n template: getTemplate() // 使用模版\\r\\n })\\r\\n ],\\r\\n resolve: {\\r\\n extensions: [\'.js\', \'.jsx\', \'.json\'], // 不用编写的后缀\\r\\n alias: {\\r\\n // // 配置快捷使用\\r\\n // \\"appbir_utils\\": resolve(\'./src/subproject/src/main.js\'),\\r\\n // \\"@\\": resolve(\'../\'),\\r\\n }\\r\\n },\\r\\n devServer: {\\r\\n // contentBase: path.join(__dirname, \\"\\"), //运行的根目录(转换后的目录)\\r\\n open: true, // 在运行成功后,自动打开浏览器,并保持实时更新\\r\\n port: 9000, // 自定义的端口号\\r\\n hot: true,\\r\\n // proxy: { // 服务运行的代理\\r\\n // \'/api\': { \\r\\n // target: \'https://localhost:8888\', // 代理默认地址到数据库\\r\\n // pathRewrite: {\\r\\n // \'^/api\': \'\'\\r\\n // },\\r\\n // // 默认代理服务器,会以我们实际在浏览器请求的主机名【localhost:8080】,作为代理服务器的主机名,\\r\\n // // 然后代理服务器会带上这个主机名,去请求github,然而 github是不认识 【localhost:8080】\\r\\n // // changeOrigin: true 就是以实际代理请求发生过程中的主机名去请求,如:代理服务器的主机名\\r\\n // changeOrigin: true\\r\\n // }\\r\\n // }\\r\\n }\\r\\n};\\r\\n\\r\\n\\r\\n\\r\\n/*************************************************************************************\\r\\n * \\r\\n * 支持定义配置\\r\\n * \\r\\n *************************************************************************************/\\r\\nconst { APPEND } = process.env;\\r\\n\\r\\nlet customConfig = null;\\r\\n\\r\\nif (APPEND) {\\r\\n customConfig = autoRequire(realPath(APPEND));\\r\\n} else {\\r\\n let defaultConfig = null;\\r\\n let diyPath = realPath(\'./config/server.es.append.config.js\');\\r\\n try {\\r\\n defaultConfig = autoRequire(diyPath);\\r\\n } catch (e) {\\r\\n log.mi(`use default webpack config! diy in [${diyPath}]`)\\r\\n }\\r\\n if (defaultConfig) {\\r\\n customConfig = defaultConfig(config);\\r\\n log.md(\'you define config:\', customConfig)\\r\\n }\\r\\n}\\r\\n\\r\\nmodule.exports = customConfig ? customConfig : config;"},{"name":"server.es.webpack.example.config.js","content":"// 案列\\r\\nconst { resolve } = require(\'app-lib-node\')\\r\\nconst config = require(\'./server.es.webpack.config.js\');\\r\\nconsole.log(\\"config\\",config);\\r\\nconfig.entry= {\\r\\n index: resolve(\'./example/es/index.js\'),\\r\\n},\\r\\nmodule.exports = config;"},{"name":"server.es.webpack.test.config.js","content":"const { resolve, getTemplate } = require(\'app-lib-node\')\\r\\n// 测试\\r\\nconst config = require(\'./server.es.webpack.config.js\');\\r\\nconfig.entry= {\\r\\n index: resolve(\'./example/node/index.js\'),\\r\\n},\\r\\nmodule.exports = config;"}]'); /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module is referenced by other modules so it can't be inlined /******/ var __webpack_exports__ = __webpack_require__(138); /******/ /******/ return __webpack_exports__; /******/ })() ; }); //# sourceMappingURL=index-bundle.js.map