webpack.config.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 + '/dist'),//打包生成文件地址
  9. filename: '[name].build.js',//生成文件ming
  10. publicPath: '/dist/'//文件输出的公共路径
  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'],
  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. }
  72. module.exports = config;