首页 > 解决方案 > 构建带有汇总的 Vue.js 3(测试版)应用程序时出现问题:“错误:意外的令牌(请注意,您需要插件才能导入不是 JavaScript 的文件)”

问题描述

我正在尝试使用 Rollup 构建一个 Vue.js 3 (beta) 应用程序。

我明白了:

$ npx rollup -c rollup.config.prod.js 

src/main.js → public/dist/...
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/App.vue?vue&type=style&index=0&id=7ba5bd90&scoped=true&lang.css (2:0)
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:5154:30)
    at Module.error (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:9592:16)
    at tryParse (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:9506:23)
    at Module.setSource (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:9890:30)
    at ModuleLoader.addModuleSource (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17749:20)
    at ModuleLoader.fetchModule (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17803:9)
    at async Promise.all (index 2)
    at ModuleLoader.fetchStaticDependencies (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17827:34)
    at async Promise.all (index 0)
    at ModuleLoader.fetchModule (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17804:9)
    at async Promise.all (index 3)
    at ModuleLoader.fetchStaticDependencies (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17827:34)
    at async Promise.all (index 0)
    at ModuleLoader.fetchModule (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17804:9)
    at async Promise.all (index 0)

我的汇总配置:

import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import fileSize from 'rollup-plugin-filesize';
import vue from 'rollup-plugin-vue';

const plugins = [
  resolve(),

  vue({
    template: {
      isProduction: true,
      //compilerOptions: { preserveWhitespace: false }
    },
    //css: false,   // note: 'false' extracts styles as a separate '.css' file
  }),

  replace({ 'process.env.NODE_ENV': '"production"' }),

  fileSize()
];

export default {
  plugins,
  input: 'src/main.js',

  output: {
    dir: 'public/dist/',
    format: 'esm',

    globals: {
      firebaseui: "firebaseui"
    },

    sourcemap: true   // have source map even for production
  }
};

已经苦苦寻找类似的案例,但还没有找到解决方案。有谁知道,这可能是关于什么的?

资料来源:资料来源:https ://github.com/akauppi/GroundLevel-es6-firebase-web/tree/pr-prod

标签: rollupjsvuejs3

解决方案


推荐阅读