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

使用Rollup使用Vue编译javascript时出错

百里意智
2023-03-14

我在使用汇总编译Vue脚本时遇到问题。我得到的错误是

[!] 错误:节点_modules/vue/dist/vue未导出“openBlock”。运行时。esm。js,由src/js/components/TestButton导入。vue?vue

app.js

import Vue from 'vue/dist/vue'
import Buefy from 'buefy'

Vue.use(Buefy)

import ButtonTest from './components/TestButton.vue'

Vue.component('ssm-button', ButtonTest);

var app = new Vue({
    el: '#app',
    data: {
      message: 'You loaded this page on ' + new Date().toLocaleString()
    }
})

TestButton.vue

<template>
    <div>
        asdf
    </div>
</template>
<script>
export default {}
</script>

卷起来。配置。js

'use strict'

const path = require('path')
const { babel } = require('@rollup/plugin-babel')
const banner = require('./banner.js')
const { nodeResolve } = require('@rollup/plugin-node-resolve')

import multi from '@rollup/plugin-multi-entry'
import vuePlugin from 'rollup-plugin-vue'
import replace from '@rollup/plugin-replace'
import commonjs from '@rollup/plugin-commonjs'

let fileDest = 'app.js'

const external = ['jquery']
const plugins = [
  vuePlugin(),
  replace({
    preventAssignment: true,
    'process.env.NODE_ENV': JSON.stringify( 'production' )
  }),

  babel({
    // Only transpile our source code
    exclude: 'node_modules/**',
    // Include the helpers in the bundle, at most one copy of each
    babelHelpers: 'bundled'
  }),
  nodeResolve(),
  multi(),
  commonjs(),
]
const globals = {
  jquery: 'jQuery', // Ensure we use jQuery which is always available even in noConflict mode
  'popper.js': 'Popper'
}


module.exports = [
  {
    input: [path.resolve(__dirname, '../js/app.js'), path.resolve(__dirname, '../js/custom.js')],
    output: {
      banner,
      file: path.resolve(__dirname, `../../assets/js/${fileDest}`),
      format: 'umd',
      globals,
      name: 'main-javascript'
    },
    external,
    plugins,
  },
]

我尝试了很多不同的东西,但似乎没有任何帮助。但是,如果我在配置中的vuePlugin之前加载通用js,我会得到不同的错误

[!] (plugin commonjs)SyntaxError:Unexpected token(2:4)in/Users/xxx/Dev/self storage manager/wordpress_data/wp content/themes/Bulmascores/src/js/components/TestButton。vue?vue

有人知道发生了什么吗?在过去的两天里,我一直在研究这个问题,似乎真的找不到解决办法。

共有1个答案

百里成仁
2023-03-14

终于找到了解决办法

我将rollup vue插件从@rollup/plugin-vue更改为rollup-plugin-vue2https://github.com/thgh/rollup-plugin-vue2现在它可以工作了。

 类似资料:
  • 给出了以下简单的项目结构。 内容是

  • 我已经为Raspberry PI使用了已经编译好的openCV版本。任何感兴趣的人的链接 //usr/local/lib/libopencv_calib3d.so.2.4:未定义对`CV::Mutex::Unlock()'的引用 //usr/local/lib/libopencv_calib3d.so.2.4:未定义对`CV::mutex::lock()‘的引用 //usr/local/lib/l

  • 我想做的是:使用msvc 2010或更高版本编译qt-everywhere_opensource-4.7.3、qwt、qtwtplot3d和qwt极。 我所做的: > 安装Visual Studio C Express 2010 下载代码源文件“qt-无处不在-开源-src-4.7.3” 在"C:\Qt\静态"a中提取zip的内容。小心更改目录的名称。它们必须很短,没有空格。 创建环境变量a.QM

  • 我试图用maven在heroku simple servlet上上传。在本地,我的servlet工作正常,但当我使用: 我得到“构建失败”的错误消息: 我在系统变量中将所有内容都更改为Java 1.7,maven运行的是Java 1.7,javac版本是1.7? 我在这里错过了什么吗? 编辑:我的JAVA_HOME和错误截图

  • 我目前正在尝试将基于Ant的构建过程转移到Gradle。 任务“:CompileJava”执行失败。编译失败;有关详细信息,请参阅编译器错误输出。“ -stacktrace选项不提供其他信息。所以,Gradle编译显示我的代码中有一些错误。但是这个相同的代码(Ant jar任务的jar)目前被20个或更多的其他项目使用,一切都是可以的。 Gradle似乎是一个很棒的构建工具,所以我想理解为什么当我

  • 使用汇总打包Vue组件时,会出现此错误: 卷起来。配置。js: 按钮vue: 有解决办法吗? 所以我找到了一个更好的方法: 最好使用vue sfc汇总来打包vue组件。