webpack.config.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const path=require('path');
  2. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  3. //const { HtmlWebpackPlugin } = require("html-webpack-plugin");
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. //const { VueLoaderPlugin } = require('vue-loader/dist/index');
  6. const { VueLoaderPlugin } = require('vue-loader');
  7. module.exports={
  8. entry:"./index.js",
  9. output:{
  10. filename:"bundle.js",
  11. path:path.resolve(__dirname,"./dist")
  12. },
  13. resolve: {
  14. alias: {
  15. vue: 'vue/dist/vue.esm-bundler.js' // 关键配置
  16. }
  17. },
  18. module:{
  19. rules:[
  20. {
  21. test:/\.css$/i,
  22. use:["style-loader","css-loader"]
  23. },
  24. {
  25. test:/\.vue$/,
  26. use:[
  27. { loader:"vue-loader" }
  28. ]
  29. },
  30. // 处理 .js 文件
  31. {
  32. test: /\.js$/,
  33. loader: 'babel-loader',
  34. exclude: /node_modules/
  35. }]
  36. },
  37. plugins:[
  38. new VueLoaderPlugin(),
  39. new CleanWebpackPlugin(),
  40. new HtmlWebpackPlugin({
  41. inject:'body',
  42. title:"webpack sample ",
  43. template:"./index.html"
  44. })
  45. ]
  46. }