UNPKG

ykpm

Version:

基于webpak封装的打包工具,集成打包、调试、代理、ajax劫持模拟数据

55 lines (41 loc) 1.46 kB
'use strict'; const fs = require('fs'); const path = require('path'); const webpack = require('./initWebpack'); const webpackServer = require('./initWebpackDevServer'); const moduleResolvePath = require('./utils').moduleResolvePath; module.exports = { run: (cwd, args, argv) => { let config = null; let configPath = path.join(cwd, argv.config || './package.json'); if (fs.existsSync(configPath)) { config = JSON.parse(fs.readFileSync(configPath), 'utf-8'); } if (config === null) { process.exit(); } let ykpm = config.ykpm || { build: {}, debug: {} }; let serverConfig = ykpm.debug || {}; let webpackConfig = ykpm.build || {}; let isListenHostname = true; serverConfig.cwd = cwd; if (!serverConfig.hostname) { isListenHostname = false; serverConfig.hostname = 'localhost'; } if (!serverConfig.port) { serverConfig.port = 8080; } let devClient = [`${moduleResolvePath('webpack-dev-server/client')}?http://${serverConfig.hostname}:${serverConfig.port}`]; if (serverConfig.hot) { devClient.push(moduleResolvePath('webpack/hot/dev-server')); } webpackConfig.debug = true; webpackConfig.devClient = devClient; webpackConfig.option = webpackConfig.option || {}; webpackConfig.option.cssExtract = false; let compiler = webpack(cwd, webpackConfig); let server = webpackServer(compiler, serverConfig); server.listen(serverConfig.port, isListenHostname ? serverConfig.hostname : ''); } };