0

我正在尝试rollup-plugin-skypin通过snowpack. snowpack-plugin-rollup-bundle我有一个像这样设置的小项目:

雪包.config.mjs

// Snowpack Configuration File
// See all supported options: https://www.snowpack.dev/reference/configuration
import { skypin } from 'rollup-plugin-skypin';

/** @type {import("snowpack").SnowpackUserConfig } */
export default {
  mount: {
    src: '/src/'
  },
  plugins: [
    [
      "snowpack-plugin-rollup-bundle",
      {
        extendConfig: (config) => {
          config.inputOptions.plugins.push(skypin())
          config.inputOptions.input = 'index.js'
          config.outputOptions.file = 'dist/index.js'
          config.outputOptions.format = 'esm'
          return config
        }
      }
    ]
  ],
  packageOptions: {
    /* rollup: {
      options: {
        input: 'src/index.js',
        output: {
          file: 'dist/index.js',
          format: 'esm'
        }
      }
    } */
  },
  devOptions: {
    /* ... */
  },
  buildOptions: {
    clean: true
  },
};

包.json

{
  "name": "test",
  "version": "1.0.0",
  "license": "MIT",
  "type": "module",
  "devDependencies": {
    "hueman": "^2.1.3",
    "rollup": "^2.56.3",
    "rollup-plugin-skypin": "^1.1.2",
    "skypin": "^2.0.10",
    "snowpack": "^3.8.8",
    "snowpack-plugin-rollup-bundle": "^0.4.4"
  },
  "scripts": {
    "start": "snowpack dev",
    "build": "snowpack build"
  }
}

index.js

// src/index.js
import { hueman } from 'hueman';

console.log(hueman(100,1.0,0.5));

然后在运行时出现此错误yarn build

[17:48:10] [snowpack] ! optimizing build...
Error fetching module from skypack. Returning empty strings
ReferenceError: fetch is not defined
    at fetchSkypack (file:///C:/test/node_modules/skypin/dist/browser.mjs:52:22)
    at lookup (file:///C:/test/node_modules/skypin/dist/browser.mjs:47:61)
    at skypin (file:///C:/test/node_modules/skypin/dist/browser.mjs:40:18)
    at Object.resolveId (file:///C:/test/node_modules/rollup-plugin-skypin/dist/index.mjs:27:31)
    at C:\test\node_modules\rollup\dist\shared\rollup.js:20218:25
[17:48:10] [snowpack-plugin-rollup-bundle] Error: Entry module cannot be external (index.js).
error Command failed with exit code 1.

这个错误是什么意思?有没有可能让所有东西一起工作?

4

1 回答 1

0

原来这个功能是内置在 Snowpack 中的,但需要一些挖掘才能找到它。

https://github.com/TropicalRaisel/avalanche

于 2021-09-03T16:07:48.923 回答