【问题标题】:Getting Snowpack to work with the Skypin Rollup plugin让 Snowpack 与 Skypin Rollup 插件一起工作
【发布时间】:2021-09-03 00:01:11
【问题描述】:

我正在尝试让 rollup-plugin-skypin 与 snowpack 到 snowpack-plugin-rollup-bundle 一起工作。我有一个像这样设置的小项目:

snowpack.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
  },
};

package.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.

这个错误是什么意思?是否有可能让所有东西协同工作?

【问题讨论】:

    标签: rollupjs snowpack skypack-cdn


    【解决方案1】:

    原来这个功能是内置在 Snowpack 中的,但花了一些时间才找到它。

    https://github.com/TropicalRaisel/avalanche

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 2020-09-10
      • 2021-03-14
      • 2021-10-17
      相关资源
      最近更新 更多