视频播放器仓库

start.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* eslint-disable no-console */
  2. const path = require('path');
  3. const pkg = require('./../package.json');
  4. const express = require('express');
  5. const webpack = require('webpack');
  6. const detect = require('detect-port');
  7. const chalk = require('chalk');
  8. const open = require('open');
  9. const webpackDevMiddleware = require('webpack-dev-middleware');
  10. const webpackHotMiddleware = require('webpack-hot-middleware');
  11. const generateDemoConfig = require('./../demo/generateConfig');
  12. const generateComponentConfig = require('./../generateConfig');
  13. const app = express();
  14. const compiler = webpack([
  15. generateComponentConfig({
  16. // Build the component library into node_modules
  17. // so we need not do a symlink for development.
  18. outputPath: path.resolve(__dirname, '../demo/node_modules/' + pkg.name + '/dist')
  19. }),
  20. generateDemoConfig({
  21. hot: true,
  22. optimize: false,
  23. extractCss: false
  24. })
  25. ]);
  26. const [componentCompiler, demoCompiler] = compiler.compilers;
  27. componentCompiler.watch({}, function(err) {
  28. if (err) {
  29. throw err;
  30. }
  31. });
  32. app.use(webpackDevMiddleware(demoCompiler));
  33. app.use(webpackHotMiddleware(demoCompiler));
  34. const run = (port) => {
  35. detect(port, (err, _port) => {
  36. if (port === _port) {
  37. app.listen(_port, () => {
  38. const url = `http://localhost:${port}`;
  39. console.log(chalk.cyan(`Server running at ${url}.`));
  40. open(url);
  41. });
  42. } else {
  43. run(port + 1);
  44. }
  45. });
  46. };
  47. run(6060);