webpack.dev.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. var path = require('path')
  2. var webpack = require('webpack')
  3. const WebpackMerge = require('webpack-merge')
  4. const baseConfig = require('./webpack.base.js')
  5. let HtmlWebpackPlugin = require('html-webpack-plugin');
  6. module.exports = WebpackMerge.merge(baseConfig, {
  7. mode: 'development',
  8. entry: path.join(__dirname, 'examples/main.js'), // 入口文件
  9. output: {
  10. path: path.join(__dirname, 'dist'), // 打包后文件存放的地方
  11. filename: 'dist/build.js' // 打包后输出的文件名
  12. },
  13. devServer: {
  14. port: 8086,
  15. historyApiFallback: true,
  16. proxy: {
  17. '/api': {
  18. //要访问的跨域的域名
  19. target: 'http://127.0.0.1:83/',
  20. ws: true, // 是否启用websockets
  21. //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样客户端端和服务端进行数据的交互就不会有跨域问题
  22. changOrigin: true,
  23. }
  24. }
  25. },
  26. devtool: 'source-map',
  27. plugins: (module.exports.plugins || []).concat([
  28. new HtmlWebpackPlugin({ // html-webpack-plugin 插件对象
  29. template: path.join(__dirname, './index.html'), // 指定模板文件
  30. filename: 'index.html' // 设置内存中的文件名
  31. })
  32. ])
  33. })