webpack4.x 1:1 还原 vue-cli创建的项目!!!

本文档详细介绍了如何使用Webpack从头配置一个Vue项目,包括模块热替换、多进程JS压缩、样式独立文件、Babel全IE9兼容、CDN外部加载、Treeshaking以及ant-design-vue按需加载等关键配置。通过这些配置,可以提升项目性能并优化开发体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目目录

先看一下目录,是不是似曾相识?

├── dist
├── public
│   └── index.html
├── src
│   ├── assets
│   │   ├── css
│   │   └── img
│   ├── components
│   ├── plugins
│   │   ├── antdv.js
│   │   └── Dot.js
│   ├── router
│   │   └── index.js
│   ├── store
│   │   └── index.js
│   ├── utils
│   │   ├── index.js
│   │   ├── RegExp.js
│   │   └── request.js
│   ├── views
│   │   ├── Home.vue
│   │   └── Login.vue
│   ├── App.vue
│   └── main.js
├── .browserslistrc
├── babel.config.js
├── package-lock.json
├── package.json
├── webpack.config.js
└── yarn.lock

前言

众所周知,vue-cli 实际上就是基于 webpack 封装的一个工具,它默认保留了一些常用的配置,我们甚至不需要对于 webpack 有多深的了解都能很好的开发vue项目。但是使用 webpack 从0配置一个 vue项目还是一件很有意思的事。
首先声明本篇不会教你写 webpackhello world官方文档 就是最好的入门教程。我也是在看完官方文档后在网上没有找到一篇自己想要的配置,只好自己写一篇,希望能给到看标题进来的人一些帮助。

它具有哪些功能

介绍一些本篇配置具有的功能和一些概念,有助于对于webpack有一个整体性的认知。

  • 模块热替换(类似于热更新、热部署,它可以无刷新更新页面👍)
  • 多进程并行压缩js(显著提高打包的速度、显著减小文件大小👍)
  • 提取样式为 .css 文件(默认方式为将 style字符串 插入到页面中,提取为单文件可以显著节省加载时间👍)
  • 配置 babel,全兼容 IE9及以上(需求再无理也能克服👍后面会放一个网址作为预览,部分样式就没考虑IE9了😅)
  • 配置部分js使用 cdn 外部加载(显著提高首屏加载速度、显著减少打包文件大小👍)
  • tree shaking (筛除没有用到的 ES模块,显著减少打包文件大小👍)
  • 整合 ant-design-vue 按需加载、主题色配置(显著减少打包文件大小👍)

以上几乎是重要功能的全部了,下面直接贴配置。

webpack.config.js

const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
// 使用解构引入,webpack 中文文档教程该块代码已过时
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const Webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
// 多进程并行压缩js插件
const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')

const WebpackConfig = {
  // 入口js
  entry: {
    app: './src/main.js',
  },
  output: {
    // 输出路径 - 不存在即创建文件夹
    path: path.resolve(__dirname, 'dist'),
    // 输出文件名称
    filename: '[name].js',
    // 打包后资源的地址前缀 - 目前只有在 webpack-dev-middleware 中使用
    publicPath: './'
  },
  module: {
    rules: [
      {
        test: /\.(css|less)$/,
        // 提取 css 为 .css文件 引入
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          {
            loader: 'less-loader',
            options: {
              lessOptions: {
                modifyVars: {
                  'primary-color': '#1DA57A',
                  'link-color': '#1DA57A',
                  'border-radius-base': '2px',
                },
                javascriptEnabled: true
              }
            },
          }
        ],
      },
      {
        // 加载图片
        test: /\.(png|jpg)$/, use: ['file-loader']
      },
      {
        // 加载字体
        test: /\.(woff|woff2|eot|ttf|otf)$/, use: ['file-loader']
      },
      {
        // 加载vue文件
        test: /\.vue$/, use: ['vue-loader']
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ['@babel/preset-env']
          }
        }
      }
    ],
  },
  plugins: [
    // 优化 moment.js
    new Webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    // 压缩js插件
    new ParallelUglifyPlugin({
      uglifyJS: {},
      test: /.js$/g,
      include: [],
      exclude: [],
      cacheDir: '',
      workerCount: '',
      sourceMap: false
    }),
    new VueLoaderPlugin(),
    // 更改您的配置文件以告诉 CleanWebpackPlugin 我们不想在监视触发增量构建后删除 index.html 文件,我们可以使用 cleanStaleWebpackAssets 选项来执行此操作:
    new CleanWebpackPlugin({cleanStaleWebpackAssets: false}),
    // 提取 css
    new MiniCssExtractPlugin(),
    // 生成 html 文件,并将生成的所有 bundle文件 自动引入到 html中
    new HtmlWebpackPlugin({
      // 初始模板
      template: './public/index.html',
      // cdn不是HtmlWebpackPlugin默认配置, 但可在index.html中 以 'htmlWebpackPlugin.options.cdn.js' 读取数据
      cdn: {
        js: [
          'https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js',
          'https://cdn.jsdelivr.net/npm/vue-router@3.1.3/dist/vue-router.min.js',
          'https://cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js'
        ]
      }
    }),
    // 当开启 HMR 的时候使用该插件会显示模块的相对路径,建议用于开发环境。
    new Webpack.NamedModulesPlugin(),
    // 模块热替换插件
    new Webpack.HotModuleReplacementPlugin()
  ],
  resolve: {
    // 配置路径别名
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  // 用于开发环境的错误调试定位
  devtool: '(none)',
  devServer: {
    // 告诉服务器从哪里提供内容
    contentBase: './public',
    // 在浏览器中打开
    open: true,
    // 端口号
    port: 8080,
    // 启用 webpack 的模块热替换(ps:不刷新页面更新代码)
    hot: true,
    // 假设服务器运行在 http://localhost:8080 并且 output.filename 被设置为 bundle.js。默认 publicPath 是 "/",所以你的包(bundle)可以通过 http://localhost:8080/bundle.js 访问。
    publicPath: '/'
  },
  // 以下js使用cdn外部引入
  externals: {
    vue: 'Vue',
    'vue-router': 'VueRouter',
    vuex: 'Vuex'
  }
}

又贴了这么长的代码😓,以上便是我尝试使用 webpack 1:1 还原 vue-cli 项目的全部了,当然 1:1 是有些吹了😋。我建议初学webpack的同学将 官方例子 全部敲一遍,相信我官方例子绝对通俗易学。耐心啃完官方教程然后再来配置一个vue项目应该就非常得心应手了,本篇是一篇 使用webpack起手配置vue项目 博文。或许在自己的实践中,有人会遇到不同的坑,填坑之路绝对是充满乐趣的。学会一个东西都是从踩坑到熟练的过程,加油💪。

源码

可在 该地址 直接拉取源码,以供参考。

error in ./src/components/Container.vue?vue&type=script&lang=js Module not found: Error: [CaseSensitivePathsPlugin] `C:\Users\14949\caovue\src\components\nav.vue` does not match the corresponding path on disk `Nav.vue`. ERROR in ./src/components/Container.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/Container.vue?vue&type=script&lang=js) 1:0-28 Module not found: Error: [CaseSensitivePathsPlugin] `C:\Users\14949\caovue\src\components\nav.vue` does not match the corresponding path on disk `Nav.vue`. @ ./src/components/Container.vue?vue&type=script&lang=js 1:0-202 1:218-221 1:223-422 1:223-422 @ ./src/components/Container.vue 2:0-60 3:0-55 3:0-55 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js 4:0-51 12:4-13 @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 11:17-20 webpack compiled with 1 error WAIT Compiling... 16:57:24 Compiling... DONE Compiled successfully in 314ms 16:57:25 App running at: - Local: http://localhost:8080/ - Network: http://192.168.164.19:8080/ WAIT Compiling... 16:57:27 Compiling... DONE Compiled successfully in 453ms 16:57:28 App running at: - Local: http://localhost:8080/ - Network: http://192.168.164.19:8080/ WAIT Compiling... 16:57:31 Compiling... DONE Compiled successfully in 366ms 16:57:31 App running at: - Local: http://localhost:8080/ - Network: http://192.168.164.19:8080/ WAIT Compiling... 16:57:33 Compiling... DONE Compiled successfully in 265ms 16:57:33 App running at: - Local: http://localhost:8080/ - Network: http://192.168.164.19:8080/ WAIT Compiling... 16:57:39 Compiling... DONE Compiled successfully in 280ms 16:57:39 App running at: - Local: http://localhost:8080/ - Network: http://192.168.164.19:8080/ * 还原的历史记录 PS C:\Users\14949\caovue> npm run serve > caovue@0.1.0 serve > vue-cli-service serve INFO Starting development server... ERROR Failed to compile with 1 error 14:24:19 error in ./src/App.vue?vue&type=script&lang=js Module not found: Error: Can't resolve './components/SchoolO.vue' in 'C:\Users\14949\caovue\src' ERROR in ./src/App.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js) 3:0-46 Module not found: Error: Can't resolve './components/SchoolO.vue' in 'C:\Users\14949\caovue\src' @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 5:17-20 webpack compiled with 1 error WAIT Compiling... 14:24:20 Compiling... ERROR Failed to compile with 1 error 14:24:20 error in ./src/App.vue?vue&type=script&lang=js Module not found: Error: Can't resolve './components/SchoolO.vue' in 'C:\Users\14949\caovue\src' ERROR in ./src/App.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js) 3:0-46 Module not found: Error: Can't resolve './components/SchoolO.vue' in 'C:\Users\14949\caovue\src' @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 5:17-20 webpack compiled with 1 error PS C:\Users\14949\caovue> npm run serve > caovue@0.1.0 serve > vue-cli-service serve INFO Starting development server... ERROR Failed to compile with 1 error 14:56:01 error in ./src/components/tu.vue?vue&type=script&lang=js Module not found: Error: Can't resolve '@/assets/520images/疯狂动物城.jpg' in 'C:\Users\14949\caovue\src\components' ERROR in ./src/components/tu.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/tu.vue?vue&type=script&lang=js) 11:13-52 Module not found: Error: Can't resolve '@/assets/520images/疯狂动物城.jpg' in 'C:\Users\14949\caovue\src\components' @ ./src/components/tu.vue?vue&type=script&lang=js 1:0-195 1:211-214 1:216-408 1:216-408 @ ./src/components/tu.vue 2:0-53 3:0-48 3:0-48 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/Button.vue?vue&type=script&lang=js 1:0-26 @ ./src/components/Button.vue?vue&type=script&lang=js 1:0-199 1:215-218 1:220-416 1:220-416 @ ./src/components/Button.vue 2:0-57 3:0-52 3:0-52 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js 3:0-45 10:4-10 @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 11:17-20 webpack compiled with 1 error WAIT Compiling... 14:56:01 Compiling... ERROR Failed to compile with 1 error 14:56:02 error in ./src/components/Button.vue?vue&type=script&lang=js Syntax Error: C:\Users\14949\caovue\src\components\Button.vue: Missing semicolon. (21:3) 19 | } 20 | } > 21 | }, | ^ 22 | components: { 23 | tu 24 | } at parser.next (<anonymous>) at normalizeFile.next (<anonymous>) at run.next (<anonymous>) at transform.next (<anonymous>) ERROR in ./src/components/Button.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/Button.vue?vue&type=script&lang=js) Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: C:\Users\14949\caovue\src\components\Button.vue: Missing semicolon. (21:3) 19 | } 20 | } > 21 | }, | ^ 22 | components: { 23 | tu 24 | } at constructor (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:363:19) at JSXParserMixin.raise (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:6609:19) at JSXParserMixin.semicolon (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:6906:10) at JSXParserMixin.parseExportDefaultExpression (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13841:10) at JSXParserMixin.parseExport (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13743:25) at JSXParserMixin.parseStatementContent (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12797:27) at JSXParserMixin.parseStatementLike (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12685:17) at JSXParserMixin.parseModuleItem (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12662:17) at JSXParserMixin.parseBlockOrModuleBlockBody (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13235:36) at JSXParserMixin.parseBlockBody (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13228:10) at JSXParserMixin.parseProgram (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12541:10) at JSXParserMixin.parseTopLevel (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12531:25) at JSXParserMixin.parse (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:14410:10) at parse (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:14423:26) at parser (C:\Users\14949\caovue\node_modules\@babel\core\lib\parser\index.js:41:34) at parser.next (<anonymous>) at normalizeFile (C:\Users\14949\caovue\node_modules\@babel\core\lib\transformation\normalize-file.js:64:37) at normalizeFile.next (<anonymous>) at run (C:\Users\14949\caovue\node_modules\@babel\core\lib\transformation\index.js:22:50) at run.next (<anonymous>) at transform (C:\Users\14949\caovue\node_modules\@babel\core\lib\transform.js:22:33) at transform.next (<anonymous>) at step (C:\Users\14949\caovue\node_modules\gensync\index.js:261:32) at C:\Users\14949\caovue\node_modules\gensync\index.js:273:13 at async.call.result.err.err (C:\Users\14949\caovue\node_modules\gensync\index.js:223:11) @ ./src/components/Button.vue?vue&type=script&lang=js 1:0-199 1:215-218 1:220-416 1:220-416 @ ./src/components/Button.vue 2:0-57 3:0-52 3:0-52 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js 3:0-45 10:4-10 @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 11:17-20 webpack compiled with 1 error WAIT Compiling... 14:56:19 Compiling... ERROR Failed to compile with 1 error 14:56:19 error in ./src/components/Button.vue?vue&type=script&lang=js Syntax Error: C:\Users\14949\caovue\src\components\Button.vue: Unexpected token, expected "," (21:4) 19 | } 20 | } > 21 | components: { | ^ 22 | tu 23 | } 24 | }, at parser.next (<anonymous>) at normalizeFile.next (<anonymous>) at run.next (<anonymous>) at transform.next (<anonymous>) ERROR in ./src/components/Button.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/Button.vue?vue&type=script&lang=js) Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: C:\Users\14949\caovue\src\components\Button.vue: Unexpected token, expected "," (21:4) 19 | } 20 | } > 21 | components: { | ^ 22 | tu 23 | } 24 | }, at constructor (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:363:19) at JSXParserMixin.raise (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:6609:19) at JSXParserMixin.unexpected (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:6629:16) at JSXParserMixin.expect (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:6910:12) at JSXParserMixin.parseObjectLike (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:11755:14) at JSXParserMixin.parseExprAtom (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:11270:23) at JSXParserMixin.parseExprAtom (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:4776:20) at JSXParserMixin.parseExprSubscripts (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:11012:23) at JSXParserMixin.parseUpdate (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10997:21) at JSXParserMixin.parseMaybeUnary (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10977:23) at JSXParserMixin.parseMaybeUnaryOrPrivate (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10830:61) at JSXParserMixin.parseExprOps (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10835:23) at JSXParserMixin.parseMaybeConditional (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10812:23) at JSXParserMixin.parseMaybeAssign (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10765:21) at C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10734:39 at JSXParserMixin.allowInAnd (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12356:16) at JSXParserMixin.parseMaybeAssignAllowIn (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10734:17) at JSXParserMixin.parseExportDefaultExpression (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13840:22) at JSXParserMixin.parseExport (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13743:25) at JSXParserMixin.parseStatementContent (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12797:27) at JSXParserMixin.parseStatementLike (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12685:17) at JSXParserMixin.parseModuleItem (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12662:17) at JSXParserMixin.parseBlockOrModuleBlockBody (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13235:36) at JSXParserMixin.parseBlockBody (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13228:10) at JSXParserMixin.parseProgram (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12541:10) at JSXParserMixin.parseTopLevel (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12531:25) at JSXParserMixin.parse (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:14410:10) at parse (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:14423:26) at parser (C:\Users\14949\caovue\node_modules\@babel\core\lib\parser\index.js:41:34) at parser.next (<anonymous>) at normalizeFile (C:\Users\14949\caovue\node_modules\@babel\core\lib\transformation\normalize-file.js:64:37) at normalizeFile.next (<anonymous>) at run (C:\Users\14949\caovue\node_modules\@babel\core\lib\transformation\index.js:22:50) at run.next (<anonymous>) at transform (C:\Users\14949\caovue\node_modules\@babel\core\lib\transform.js:22:33) at transform.next (<anonymous>) at step (C:\Users\14949\caovue\node_modules\gensync\index.js:261:32) at C:\Users\14949\caovue\node_modules\gensync\index.js:273:13 at async.call.result.err.err (C:\Users\14949\caovue\node_modules\gensync\index.js:223:11) @ ./src/components/Button.vue?vue&type=script&lang=js 1:0-199 1:215-218 1:220-416 1:220-416 @ ./src/components/Button.vue 2:0-57 3:0-52 3:0-52 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js 3:0-45 10:4-10 @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 11:17-20 webpack compiled with 1 error WAIT Compiling... 14:56:20 Compiling... ERROR Failed to compile with 1 error 14:56:21 error in ./src/components/Button.vue?vue&type=script&lang=js Syntax Error: C:\Users\14949\caovue\src\components\Button.vue: Unexpected token, expected "," (21:4) 19 | } 20 | } > 21 | components: { | ^ 22 | tu 23 | } 24 | } at parser.next (<anonymous>) at normalizeFile.next (<anonymous>) at run.next (<anonymous>) at transform.next (<anonymous>) ERROR in ./src/components/Button.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/Button.vue?vue&type=script&lang=js) Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: C:\Users\14949\caovue\src\components\Button.vue: Unexpected token, expected "," (21:4) 19 | } 20 | } > 21 | components: { | ^ 22 | tu 23 | } 24 | } at constructor (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:363:19) at JSXParserMixin.raise (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:6609:19) at JSXParserMixin.unexpected (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:6629:16) at JSXParserMixin.expect (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:6910:12) at JSXParserMixin.parseObjectLike (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:11755:14) at JSXParserMixin.parseExprAtom (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:11270:23) at JSXParserMixin.parseExprAtom (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:4776:20) at JSXParserMixin.parseExprSubscripts (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:11012:23) at JSXParserMixin.parseUpdate (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10997:21) at JSXParserMixin.parseMaybeUnary (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10977:23) at JSXParserMixin.parseMaybeUnaryOrPrivate (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10830:61) at JSXParserMixin.parseExprOps (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10835:23) at JSXParserMixin.parseMaybeConditional (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10812:23) at JSXParserMixin.parseMaybeAssign (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10765:21) at C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10734:39 at JSXParserMixin.allowInAnd (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12356:16) at JSXParserMixin.parseMaybeAssignAllowIn (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:10734:17) at JSXParserMixin.parseExportDefaultExpression (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13840:22) at JSXParserMixin.parseExport (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13743:25) at JSXParserMixin.parseStatementContent (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12797:27) at JSXParserMixin.parseStatementLike (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12685:17) at JSXParserMixin.parseModuleItem (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12662:17) at JSXParserMixin.parseBlockOrModuleBlockBody (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13235:36) at JSXParserMixin.parseBlockBody (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:13228:10) at JSXParserMixin.parseProgram (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12541:10) at JSXParserMixin.parseTopLevel (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:12531:25) at JSXParserMixin.parse (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:14410:10) at parse (C:\Users\14949\caovue\node_modules\@babel\parser\lib\index.js:14423:26) at parser (C:\Users\14949\caovue\node_modules\@babel\core\lib\parser\index.js:41:34) at parser.next (<anonymous>) at normalizeFile (C:\Users\14949\caovue\node_modules\@babel\core\lib\transformation\normalize-file.js:64:37) at normalizeFile.next (<anonymous>) at run (C:\Users\14949\caovue\node_modules\@babel\core\lib\transformation\index.js:22:50) at run.next (<anonymous>) at transform (C:\Users\14949\caovue\node_modules\@babel\core\lib\transform.js:22:33) at transform.next (<anonymous>) at step (C:\Users\14949\caovue\node_modules\gensync\index.js:261:32) at C:\Users\14949\caovue\node_modules\gensync\index.js:273:13 at async.call.result.err.err (C:\Users\14949\caovue\node_modules\gensync\index.js:223:11) @ ./src/components/Button.vue?vue&type=script&lang=js 1:0-199 1:215-218 1:220-416 1:220-416 @ ./src/components/Button.vue 2:0-57 3:0-52 3:0-52 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js 3:0-45 10:4-10 @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 11:17-20 webpack compiled with 1 error WAIT Compiling... 14:56:23 Compiling... ERROR Failed to compile with 1 error 14:56:23 error in ./src/components/tu.vue?vue&type=script&lang=js Module not found: Error: Can't resolve '@/assets/520images/疯狂动物城.jpg' in 'C:\Users\14949\caovue\src\components' ERROR in ./src/components/tu.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/tu.vue?vue&type=script&lang=js) 11:13-52 Module not found: Error: Can't resolve '@/assets/520images/疯狂动物城.jpg' in 'C:\Users\14949\caovue\src\components' @ ./src/components/tu.vue?vue&type=script&lang=js 1:0-195 1:211-214 1:216-408 1:216-408 @ ./src/components/tu.vue 2:0-53 3:0-48 3:0-48 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/Button.vue?vue&type=script&lang=js 1:0-26 21:4-6 @ ./src/components/Button.vue?vue&type=script&lang=js 1:0-199 1:215-218 1:220-416 1:220-416 @ ./src/components/Button.vue 2:0-57 3:0-52 3:0-52 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js 3:0-45 10:4-10 @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 11:17-20 webpack compiled with 1 error WAIT Compiling... 14:56:27 Compiling... ERROR Failed to compile with 1 error 14:56:27 error in ./src/components/tu.vue?vue&type=script&lang=js Module not found: Error: Can't resolve '@/assets/520images/疯狂动物城.jpg' in 'C:\Users\14949\caovue\src\components' ERROR in ./src/components/tu.vue?vue&type=script&lang=js (./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/tu.vue?vue&type=script&lang=js) 11:13-52 Module not found: Error: Can't resolve '@/assets/520images/疯狂动物城.jpg' in 'C:\Users\14949\caovue\src\components' @ ./src/components/tu.vue?vue&type=script&lang=js 1:0-195 1:211-214 1:216-408 1:216-408 @ ./src/components/tu.vue 2:0-53 3:0-48 3:0-48 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/Button.vue?vue&type=script&lang=js 1:0-26 21:4-6 @ ./src/components/Button.vue?vue&type=script&lang=js 1:0-199 1:215-218 1:220-416 1:220-416 @ ./src/components/Button.vue 2:0-57 3:0-52 3:0-52 10:2-8 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/App.vue?vue&type=script&lang=js 3:0-45 10:4-10 @ ./src/App.vue?vue&type=script&lang=js 1:0-190 1:206-209 1:211-398 1:211-398 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 10:2-8 @ ./src/main.js 2:0-28 11:17-20 webpack compiled with 1 error
最新发布
06-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

帝尊菜鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值