Javascript rollup.js svelte捆绑包未在index.html中激活

Javascript rollup.js svelte捆绑包未在index.html中激活,javascript,server,svelte,rollup,Javascript,Server,Svelte,Rollup,我正在尝试部署我的svelte项目,但在livereload插件之外激活捆绑javascript时遇到了问题。当我运行rollup-c-w时,代码显示得很好,但是使用其他服务器服务应用程序不会激活JavaCScript。它至少应该是console.log,并希望添加html,但它只显示一个空白页面 rollup.config.js import svelte from "rollup-plugin-svelte"; import resolve from "@rol

我正在尝试部署我的svelte项目,但在livereload插件之外激活捆绑javascript时遇到了问题。当我运行rollup-c-w时,代码显示得很好,但是使用其他服务器服务应用程序不会激活JavaCScript。它至少应该是console.log,并希望添加html,但它只显示一个空白页面

rollup.config.js

import svelte from "rollup-plugin-svelte";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import livereload from "rollup-plugin-livereload";
import replace from "@rollup/plugin-replace";
import { terser } from "rollup-plugin-terser";
import postcss from "rollup-plugin-postcss";
import babel from "rollup-plugin-babel";

export default {
  input: "src/main.js",
  output: {
    sourcemap: true,
    format: "iife",
    name: "app",
    file: "public/build/bundle.js"
  },
  plugins: [
    babel({
      exclude: "node_modules/**"
    }),
   
    svelte({
      // enable run-time checks when not in production
      dev: !production,
      // we'll extract any component CSS out into
      // a separate file - better for performance
      css: css => {
        css.write("bundle.css");
      }
    }),

    postcss(),

    // If you have external dependencies installed from
    // npm, you'll most likely need these plugins. In
    // some cases you'll need additional configuration -
    // consult the documentation for details:
    // https://github.com/rollup/plugins/tree/master/packages/commonjs
    resolve({
      browser: true,
      dedupe: ["svelte"]
    }),
    commonjs(),

    // In dev mode, call `npm run start` once
    // the bundle has been generated
    !production && serve(),

    // Watch the `public` directory and refresh the
    // browser on changes when not in production
    !production && livereload("public"),

    // If we're building for production (npm run build
    // instead of npm run dev), minify
    production && terser(),

    // for absolut imports
    // i.e., instead of
    // import Component  from "../../../../components/Component.svelte";
    // we will be able to say
    // import Component from "components/Component.svelte";
    aliases
  ],
  watch: {
    clearScreen: false
  }
};
rollup-c将输出bundle.js。下面是我的index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />

    <link rel="shortcut icon" href="/favicon.ico" />
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon.png" />
    <link rel="stylesheet" href="/build/bundle.css" />
    <link
      rel="stylesheet"
      href="/assets/vendor/@fortawesome/fontawesome-free/css/all.min.css"
    />
    <link rel="stylesheet" href="/assets/styles/tailwind.css" />
    <title>Teach Me Sensei</title>

    <script>
      if (process === undefined) {
        var process = { env: {} };
      }
    </script>
  </head>

  <body class="text-gray-800 antialiased">
    <noscript>
      <strong
        >We're sorry but notus-svelte doesn't work properly without JavaScript
        enabled. Please enable it to continue.</strong
      >
    </noscript>
    <div id="app"></div>
    <script src="/build/bundle.js"></script>
  </body>
</html>

老师,教我
如果(进程===未定义){
var进程={env:{};
}
很抱歉,没有JavaScript,notus svelte无法正常工作
启用。请使其继续。
下面是运行livereload时chrome控制台的外观图片。汇总-c-w

下面是chrome控制台在生产或其他服务器中的外观图片。rollup-c,只提供静态内容。我不确定livereload是否为javascript做了一些特殊的事情,但在我的其他服务器中,我确保为公用文件夹提供服务。我可以在控制台中查看bundle.js


好的,我已经解决了这个问题,但我不明白为什么。我将分享我的发现,并在了解更多信息后返回更新。首先,我在生产中遇到问题的原因是我试图访问{production_url}/index.html。无论出于何种原因,我无法通过调用index.html让svelte为前端添加水分,即使html可以检索所有必要的javascript和css。然而,一旦我修复了路由{production\u url}/的静态引用,它就正确地为我的应用程序添加了水分。在localhost中也可以看到同样的影响。localhost:5000/index.html不能正确水合,但localhost:5000/index.html不能水合