Svelte environment variables: Uncaught ReferenceError: __myapp is not defined

Svelte environment variables: Uncaught ReferenceError: __myapp is not defined

我正在尝试将环境变量添加到 Svelte 项目中。尝试了很多解决方案,包括 this 但我得到的只是错误“Uncaught ReferenceError: __myapp is not defined”

这篇文章似乎已经过时了,replace 函数必须包含这样的内容。查看 plugin replace.

的自述文件

将此添加到 rollup.config.js


replace({
      values: {
        __myapp: JSON.stringify({
            isProd: production,
          ...config().parsed
        }),
      },
    }),

App.svelte 文件。

<script>
  console.log(__myapp);
  const { isProd, API_URL } = __myapp;
</script>

<h4>{isProd} - {API_URL}</h4>