当前位置: 首页 > 知识库问答 >
问题:

如何在网页中使用快捷路径“@”?

缑赤岩
2023-03-14

我用我的软件包做了“npm运行构建”。json。我听到了这个消息。如何将@与网页包一起使用?

错误/节点\模块/babel加载程序/lib/节点_模块/vue加载程序/lib/selector。js?类型=脚本

但是在"npm run dev"中,它成功了。我的package.json:

"scripts": {
  "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
  ...
  "build": "cross-env NODE_ENV=production webpack --progress --hide-modules",
  ...
},
...

用这个包裹。json,它成功了:

"build": "node build/build.js",

2月6日。添加了我的webpack.config.js:

...
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
            // the "scss" and "sass" values for the lang attribute to the right configs here.
            // other preprocessors should work out of the box, no loader config like this necessary.
            'scss': [
              'vue-style-loader',
              'css-loader',
              'sass-loader'
            ],
            'sass': [
              'vue-style-loader',
              'css-loader',
              'sass-loader?indentedSyntax'
            ]
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
...

共有2个答案

龙成仁
2023-03-14

通常被称为ES6装饰器的特殊@符号可以使用babel transform插件在您的任意一个应用程序中添加。babelrc文件或网页包babel加载程序选项。我建议在生产中使用transform decorators legacy。

将插件安装到开发人员依赖项中。

npm安装--保存dev babel插件转换装饰器的旧版

使用. babelrc或webpack.config.js.配置如果您使用的是vue-loader,我认为webpack配置是必需的。

。babelrc

{
  "presets": [
    "babel-preset-env"
  ],
  "plugins": [
    "babel-plugin-transform-decorators-legacy"
  ]
}

webpack.config.jsBabel-loader选项

{
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
            query: {
              babelrc: false,
              presets: [
                'babel-preset-env'
              ],
              plugins: [
                'babel-plugin-transform-decorators-legacy'
              ]
            }
          }
        ]
      }
    ]
  }
}

webpack。配置。jsvue加载程序选项

const VueLoaderOptionsPlugin = require('vue-loader-options-plugin');
module.exports = {
  // ... other config
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            js: 'babel-loader', // additional loaders here
          }
        }
      }
      // ... other rule
    ]
  },
  plugins: [
    new VueLoaderOptionsPlugin({
      babel: { // options for babel-loader
        presets: ['babel-preset-env'],
        plugins: ['babel-plugin-transform-decorators-legacy']
      }
    }),
  ]
}

装饰器仍然是相当新的,这就是为什么它目前在最稳定的预设中不可用的原因。

阎扬
2023-03-14

若要将“@”用作路径根,您需要在网页中添加“解析”部分。配置。js,如果您使用的是标准vue cli创建的项目(或将“src”指向组件所在的源根目录):

resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      '@': resolve('src'),
    }
  }
  
 类似资料:
  • 快捷路由 快捷路由允许你快速给控制器注册路由,并且针对不同的请求类型可以设置方法前缀,例如: // 给User控制器设置快捷路由 Route::controller('user','index/User'); User控制器定义如下: <?php namespace app\index\controller; class User { public function getInfo()

  • 本文向大家介绍如何在网页中使用图片?,包括了如何在网页中使用图片?的使用技巧和注意事项,需要的朋友参考一下 要在网页上使用图像,请使用<img>标签。标签允许您添加图像源,高度,宽度,高度等。高度是替代文本属性,即当图像无法加载时可见的文本。 以下是属性- 属性 描述 Alt键 图片的备用文字 高度 图片的高度 Ismap 该图像作为服务器端图像映射 朗德斯克 图像详细说明的URL Src 图片的

  • 问题内容: 我在Socket.io中使用Express,但我不知道如何在Express路由中使用SocKet.io。 我最终在“ app.js”中这样做 我该如何定义到“ / cmp”的路由,并在其中传递var“ io”? 这样,在“ /routes/cmp.js”中,我可以执行以下操作: 一些线索? 问题答案: 高阶函数呢? 然后 作为另一种选择,有时我会将路线的格式设置为以下格式: 然后定义为

  • 新用户:从一月份开始学习Java,现在我正在使用NetBeans,如果我写这个简单的快捷方式,我会得到大量的错误。 所以IDE只是告诉我,我几乎做错了一切。在setOnKeyPressed的线路上,我得到了 我导入了所有内容,并从StackOverflow.com上的另一个问题(可能是有效的)中复制了这段代码。我只想按“esc”,并在root被聚焦的情况下关闭我的primarystage(不管是不

  • 我想在Mac OS X 10.8 Mountain Lion中禁用键盘快捷键命令-W和命令-Q。 这是因为它们会干扰我从xQuartz运行的终端内部运行的emacs命令。如何禁用键盘快捷键?

  • 我使用的是mac、chrome 69、webpack 3.8.1、css loader 1.0.0、style loader 0.19.1 我在我的网页配置中设置了如下css sourcemap: 在chrome devTool元素检查器中,它看起来像这样: 问题是,是否可以将源映射缩短为相对于我的项目根路径? 所以不是 我希望它显示为 经过一些实验,看起来css源地图独立于webpack dev