index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const { run } = require('runjs')
  2. const chalk = require('chalk')
  3. const config = require('../vue.config.js')
  4. const webpack = require('webpack')
  5. const rawArgv = process.argv.slice(2)
  6. const args = rawArgv.join(' ')
  7. if (process.env.npm_config_preview || rawArgv.includes('--preview')) {
  8. const report = rawArgv.includes('--report')
  9. run(`vue-cli-service build ${args}`)
  10. const port = 9526
  11. const publicPath = config.publicPath
  12. var connect = require('connect')
  13. var serveStatic = require('serve-static')
  14. const app = connect()
  15. resolve: {
  16. extensions: ['.js', '.vue', '.json'],
  17. alias: {
  18. 'vue$':"vue/dist/vue.esm.js",
  19. '@': resolve('src'),
  20. 'jquery':'jquery'
  21. }
  22. }
  23. app.use(
  24. publicPath,
  25. serveStatic('./dist', {
  26. index: ['index.html', '/']
  27. })
  28. )
  29. app.listen(port, function () {
  30. console.log(chalk.green(`> Preview at http://localhost:${port}${publicPath}`))
  31. if (report) {
  32. console.log(chalk.green(`> Report at http://localhost:${port}${publicPath}report.html`))
  33. }
  34. })
  35. } else {
  36. run(`vue-cli-service build ${args}`)
  37. }
  38. plugins:[
  39. new webpack.ProvidePlugin({
  40. jQuery:"jquery",
  41. $:"jquery",
  42. 'windows.jQuery':"jquery"
  43. })
  44. ]