请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

麻烦问下老师关于rollup


const rollup = require('rollup')
const inputOptions = require('./input')
const outputOptions = require('./output')

async function rollupBuild(input, output) {
    const bundle = await rollup.rollup(input) // 根据input配置进行打包
    console.log(`正在生成:${output.file}`)
    await bundle.write(output) // 根据output配置输出文件
    console.log(`${output.file}生成成功!`)
}

(async function () {
    for (let i = 0; i < outputOptions.length; i++) {
        await rollupBuild(inputOptions, outputOptions[i])
    }
})()

请问下老师我和你的配置是一样的。。和官网也是一样
build的时候总是提醒

[!] Error: Config file must export an options object, or an array of options objectshttps://rollupjs.org/guide/en/#configuration-files

我看官网都没有export,为什么一直error

正在回答 回答被采纳积分+3

2回答

提问者 hy_wang 2020-09-17 18:05:07
// 需要nodejs分析模块 所以使用Commonjs模块
const path = require("path")


module.exports = {
    input: path.resolve(__dirname, '../../src/index.js')
}
const path = require("path")
module.exports = [{
        file: path.resolve(__dirname, "../../distAll/index.global.js"),
        format: "umd",
        name: "qingfeng",
        banner: "// please use umd"
    },
    {
        file: path.resolve(__dirname, "../../distAll/index.esm.js"),
        format: "es",
        name: "qingfeng",
        banner: "// please use esm"
    },
    {
        file: path.resolve(__dirname, "../../distAll/index.cjs.js"),
        format: "cjs",
        name: "qingfeng",
        banner: "// please use commomjs"
    }
]

build的文件

// const rollup = require("rollup")
// const input = require("./input")
// const output = require("./output")



// async function build(input, output) {
//     const bundle = await rollup.rollup(input)
//     console.log(`${bundle},打包完成`)
//     await bundle.write(output)
// }


// (async function () {
//     for (let i of output) {
//         await build(input, i)
//     }
// }())

const rollup = require('rollup')
const inputOptions = require('./input')
const outputOptions = require('./output')

async function rollupBuild(input, output) {
    const bundle = await rollup.rollup(input) // 根据input配置进行打包
    console.log(`正在生成:${output.file}`)
    await bundle.write(output) // 根据output配置输出文件
    console.log(`${output.file}生成成功!`)
}

(async function () {
    for (let i = 0; i < outputOptions.length; i++) {
        await rollupBuild(inputOptions, outputOptions[i])
    }
})()


0 回复 有任何疑惑可以回复我~
扬_灵 2020-09-17 17:49:19

同学你好,这个报错信息是配置文件必须导出options为对象或是数组,你可以看一下配置文件中返回的信息是什么或者把代码上传一下,我在本地帮你定位问题。

0 回复 有任何疑惑可以回复我~
  • 提问者 hy_wang #1
    老师这个就是配置啊,我按照你的那个手记教程。打包提示这个
    回复 有任何疑惑可以回复我~ 2020-09-17 17:58:45
  • 提问者 hy_wang #2
    我重新贴一下代码,辛苦老师
    回复 有任何疑惑可以回复我~ 2020-09-17 18:01:22
  • 扬_灵 回复 提问者 hy_wang #3
    同学你好,这里的命令是node  rollup-build.js, rollup-build.js是一个node代码,而不是rollup的配置文件,rollup的API方式打包是通过require('rollup')获取rollup方法,然后调用rollup传入config配置来完成打包。这些代码必须使用node命令来执行,可以写到js文件里,node xx.js,也可以node -e [代码内容],两种方式来运行。
    回复 有任何疑惑可以回复我~ 2020-09-18 09:45:46
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信