webpack.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var path = require('path');
  2. var HtmlWebpackPlugin = require('html-webpack-plugin');
  3. var VueLoaderPlugin = require('vue-loader/lib/plugin');
  4. const webpack = require('webpack');
  5. var config = {
  6. entry: './src/main.js',
  7. output: {
  8. path: path.resolve(__dirname + '/manageWeb'),//打包生成文件地址
  9. filename: '[name].build.js',//生成文件ming
  10. // publicPath: './'//文件输出的公共路径
  11. },
  12. module: {
  13. rules: [
  14. {
  15. test: '/\.js$/',
  16. use: [
  17. {
  18. loader: 'babel-loader',
  19. options: {
  20. presets: ['env']
  21. }
  22. }
  23. ],
  24. include: path.resolve(__dirname + '/src/'),
  25. exclude: /node_modules/,
  26. },
  27. {
  28. test: /\.css$/,
  29. use:['style-loader','css-loader']
  30. },
  31. {
  32. test: /\.sass$/,
  33. use:['vue-style-loader', 'css-loader', 'sass-loader' ],
  34. include: path.resolve(__dirname + '/src/'),
  35. exclude: /node_modules/
  36. },
  37. {
  38. test: /\.(jpg|png|gif|svg)$/,
  39. use: 'url-loader',
  40. include: path.resolve(__dirname + '/src/'),
  41. exclude: /node_modules/
  42. },
  43. {
  44. test: /\.(eot|svg|ttf|woff|woff2)$/,
  45. loader: 'file-loader'
  46. },
  47. {
  48. test: /\.vue$/,
  49. loader: 'vue-loader'
  50. }
  51. ]
  52. },
  53. resolve: {
  54. extensions: ['.js', '.jsx','.ts','.tsx', '.scss','.json','.css', '.vue'],
  55. alias: {
  56. 'vue$': 'vue/dist/vue.esm.js',
  57. "@": path.resolve(__dirname, 'src'),
  58. "components": path.resolve(__dirname, '/src/components'),
  59. "utils": path.resolve(__dirname + '/src/utils')
  60. },
  61. modules: ['node_modules']
  62. },
  63. plugins: [
  64. new HtmlWebpackPlugin({
  65. template: 'index.html',
  66. chunks: ['main']
  67. }),
  68. new VueLoaderPlugin(),
  69. new webpack.HotModuleReplacementPlugin()
  70. ],
  71. devServer: {
  72. historyApiFallback: true,
  73. noInfo: true
  74. }
  75. }
  76. module.exports = config;