• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript webpack-dev-server.listen函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中webpack-dev-server.listen函数的典型用法代码示例。如果您正苦于以下问题:TypeScript listen函数的具体用法?TypeScript listen怎么用?TypeScript listen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了listen函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: parseInt

    .action((args, cb) => {
      let port = helper.isInt(args.options.port) ? parseInt(args.options.port, 10) : 4200;
      let config = getDevConfig();
      let cssConfig = getCSSConfig();
      
      config.entry.app.unshift(`webpack-dev-server/client?http://localhost:${port}/`);
      
      let compiler = webpack([config, cssConfig]);      

      server = new webserv(compiler, {
        contentBase: './src',
        quiet: true,
        historyApiFallback: true,
        watchOptions: {
          aggregateTimeout: 1000,
          poll: 100
        }
      });

      server.listen(port, () => {
        s.status = true;
        s.port = port;
        s.ui.log(chalk.yellow(`Server running at port ${port}`));
        open(`http://localhost:${port}`);
      });

      s.server = server;

      cb();
    })
开发者ID:jkuri,项目名称:ng2-cli,代码行数:30,代码来源:start.ts


示例2: choosePort

		return choosePort(options.host, options.port).then(port => {
			if (!port) {
				throw new Error(`Port ${options.port} already in use`);
			}

			const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
			const appName = PKG.name;
			const urls = prepareUrls(protocol, options.host, port);
			// Create a webpack compiler that is configured with custom messages.
			const compiler = createCompiler(webpack, devConfig, appName, urls, false);

			const devServer = new WebpackDevServer(compiler, serverConfig);

			devServer.listen(port, options.host, err => {
				if (err) {
					return console.log(err);
				}
				console.log('Starting the devlopment server...\n');
			});

			['SIGINT', 'SIGTERM'].forEach(function(sig) {
				process.on(sig as Signals, function() {
					devServer.close();
					process.exit();
				});
			});
		});
开发者ID:sutarmin,项目名称:dx-platform,代码行数:27,代码来源:dev-server.ts


示例3: runWebpack

function runWebpack(done) {
  // https://webpack.github.io/docs/webpack-dev-server.html
  let opts = {
    host: 'localhost',
    publicPath: config.output.publicPath,
    filename: config.output.filename,
    hot: project.platform.hmr || CLIOptions.hasFlag('hmr'),
    port: project.platform.port,
    contentBase: config.output.path,
    historyApiFallback: true,
    open: project.platform.open,
    stats: {
      colors: require('supports-color')
    },
    https: config.devServer.https
  } as any;

  if (project.platform.hmr || CLIOptions.hasFlag('hmr')) {
    config.plugins.push(new webpack.HotModuleReplacementPlugin());
    config.entry.app.unshift(`webpack-dev-server/client?http://${opts.host}:${opts.port}/`, 'webpack/hot/dev-server');
  }

  const compiler = webpack(config);
  let server = new Server(compiler, opts);

  // tslint:disable-next-line:only-arrow-functions
  server.listen(opts.port, opts.host, function(err) {
    if (err) { throw err; }

    reportWebpackReadiness(opts);
    done();
  });
}
开发者ID:jbockle,项目名称:aurelia-json-schema-form,代码行数:33,代码来源:run.ts


示例4: Observable

    return new Observable(obs => {
      const devServerConfig = devServerCfg || webpackConfig.devServer || {};
      devServerConfig.host = devServerConfig.host || 'localhost';
      devServerConfig.port = devServerConfig.port || 8080;

      if (devServerConfig.stats) {
        webpackConfig.stats = devServerConfig.stats;
      }
      // Disable stats reporting by the devserver, we have our own logger.
      devServerConfig.stats = false;

      const webpackCompiler = webpack(webpackConfig);
      const server = new WebpackDevServer(webpackCompiler, devServerConfig);

      webpackCompiler.hooks.done.tap('build-webpack', (stats) => {
        // Log stats.
        loggingCb(stats, webpackConfig, this.context.logger);

        obs.next({ success: !stats.hasErrors() });
      });

      server.listen(
        devServerConfig.port,
        devServerConfig.host,
        (err) => {
          if (err) {
            obs.error(err);
          }
        },
      );

      // Teardown logic. Close the server when unsubscribed from.
      return () => server.close();
    });
开发者ID:fmalcher,项目名称:angular-cli,代码行数:34,代码来源:index.ts


示例5: Promise

 return new Promise((resolve, reject) => {
   server.listen(commandOptions.port, `${commandOptions.host}`, function(err: any, stats: any) {
     if (err) {
       console.error(err.stack || err);
       if (err.details) { console.error(err.details); }
       reject(err.details);
     }
   });
 });
开发者ID:StudioProcess,项目名称:angular-cli,代码行数:9,代码来源:serve-webpack.ts


示例6: Promise

 return new Promise((_resolve, reject) => {
   server.listen(serveTaskOptions.port, serveTaskOptions.host, (err: any, _stats: any) => {
     if (err) {
       return reject(err);
     }
     if (serveTaskOptions.open) {
       opn(serverAddress);
     }
   });
 })
开发者ID:RoPP,项目名称:angular-cli,代码行数:10,代码来源:serve.ts


示例7: Promise

  return new Promise((resolve, reject) => {
    const conf = buildConf(config)
    const routerConfig = config.router || {}
    const routerMode = routerConfig.mode === 'browser' ? 'browser' : 'hash'
    const routerBasename = routerConfig.basename || '/'
    const publicPath = conf.publicPath ? addLeadingSlash(addTrailingSlash(conf.publicPath)) : '/'
    const outputPath = path.join(appPath, conf.outputRoot as string)
    const customDevServerOption = config.devServer || {}
    const webpackChain = devConf(config)

    customizeChain(webpackChain, config.webpackChain)

    if (config.webpack) {
      warnConfigWebpack()
    }

    const devServerOptions = recursiveMerge(
      {
        publicPath,
        contentBase: outputPath,
        historyApiFallback: {
          index: publicPath
        }
      },
      baseDevServerOption,
      customDevServerOption
    )
    const devUrl = formatUrl({
      protocol: devServerOptions.https ? 'https' : 'http',
      hostname: devServerOptions.host,
      port: devServerOptions.port,
      pathname: routerMode === 'browser' ? routerBasename : '/'
    })

    const webpackConfig = webpackChain.toConfig()
    WebpackDevServer.addDevServerEntrypoints(webpackConfig, devServerOptions)
    const compiler = webpack(webpackConfig)
    bindDevLogger(devUrl, compiler)
    const server = new WebpackDevServer(compiler, devServerOptions)

    server.listen(devServerOptions.port as number, devServerOptions.disableHostCheck ? '0.0.0.0' : (devServerOptions.host as string), err => {
      if (err) {
        reject()
        return console.log(err)
      }
      resolve()

      /* 补充处理devServer.open配置 */
      if (devServerOptions.open) {
        opn(devUrl)
      }
    })
  })
开发者ID:YangShaoQun,项目名称:taro,代码行数:53,代码来源:index.ts


示例8: default

export default (PORT) => {
    config.devtool = 'eval';

    // config.entry.app.unshift(`webpack-dev-server/client?http://localhost:${PORT}/`);

    config.plugins.push(
        new webpack
            .optimize
            .CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.js', minChunks: Infinity }),
        new webpack.DefinePlugin({
            'API_URL_PREFIX': JSON.stringify('http://localhost:4999')
        })
    );

    const frontServer = new webpackDevServer(webpack(config), {
        proxy: [{
            path: '/api*',
            target: 'http://localhost:4999'
            // '/api*': {
            //     target: {
            //         'host': 'localhost',
            //         'protocol': 'http',
            //         'port': (PORT - 1)
            //     },
            //     secure: false,
            //     ignorePath: true,
            //     changeOrigin: true
            // }
        }],
        quiet: false,
        noInfo: false,
        contentBase: './src',
        historyApiFallback: true,
        inline: true,
        watchOptions: {
            aggregateTimeout: 250
        },
        stats: {
            assets: true,
            colors: true,
            version: false,
            hash: false,
            timings: true,
            chunks: false,
            chunkModules: false
        },
        publicPath: '/',
        outputPath: './wwwroot'
    });

    frontServer.listen(PORT, 'localhost');
}
开发者ID:toastermagic,项目名称:plaques,代码行数:52,代码来源:webpack-server.ts


示例9: default

export default (PORT) => {
  const server = new WebpackDevServer(webpack(config), {
    publicPath: config.output.publicPath,
    hot: true,
    ws: true,
    proxy: {
      '*' : `http://localhost:${PORT - 1}`
    }
  });

  server.listen(PORT, 'localhost');
  console.info('==> 🌎  Webpack server listening on port %s.', PORT);
}
开发者ID:BloodyEnterprise,项目名称:lazy-isomorphic-react,代码行数:13,代码来源:webpack-server.ts


示例10: prepareUrls

const buildDev = (config: BuildConfig): void => {
  const conf = Object.assign({}, buildConf, config)
  const publicPath = conf.publicPath
  const contentBase = path.join(appPath, conf.outputRoot)
  const customDevServerOptions = config.devServer || {}
  const https = 'https' in customDevServerOptions ? customDevServerOptions.https : conf.protocol === 'https'
  const host = customDevServerOptions.host || conf.host
  const port = customDevServerOptions.port || conf.port
  const urls = prepareUrls(https ? 'https' : 'http', host, port)

  const baseWebpackConf = webpackMerge(baseConf(conf), devConf(conf), {
    entry: conf.entry,
    output: {
      path: contentBase,
      filename: 'js/[name].js',
      publicPath
    }
  })

  const webpackConf = patchCustomConfig(baseWebpackConf, conf)
  const baseDevServerOptions = devServerConf({
    publicPath,
    contentBase,
    https,
    host,
    publicUrl: urls.lanUrlForConfig
  })
  const devServerOptions = Object.assign({}, baseDevServerOptions, customDevServerOptions)
  WebpackDevServer.addDevServerEntrypoints(webpackConf, devServerOptions)
  const compiler = createCompiler(webpackConf)
  compiler.hooks.done.tap('taroDoneFirst', stats => {
    if (isFirst) {
      isFirst = false
      getServeSpinner().clear()
      console.log()
      console.log(chalk.cyan(`ℹ️  Listening at ${urls.lanUrlForTerminal}`))
      console.log(chalk.cyan(`ℹ️  Listening at ${urls.localUrlForBrowser}`))
      console.log(chalk.gray('\n监听文件修改中...\n'))
    }
  })
  const server = new WebpackDevServer(compiler, devServerOptions)
  console.log()
  getServeSpinner().text = 'Compiling...'
  getServeSpinner().start()

  server.listen(port, host, err => {
    if (err) return console.log(err)
    opn(urls.localUrlForBrowser)
  })
}
开发者ID:ApolloRobot,项目名称:taro,代码行数:50,代码来源:index.ts



注:本文中的webpack-dev-server.listen函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript webpack-hot-middleware.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript webpack-dev-server.close函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap