跳至正文
Wener Notes

Rollup FAQ

约 1 分钟阅读
标签:FAQ

this has been rewritten to undefined

  • 配合 typescript 会出现,不影响使用,但很烦

忽略该错误

JavaScript
{
  onwarn(warning) {
      if (warning.code === 'THIS_IS_UNDEFINED') {
        return;
      }
      console.warn('THIS_IS_UNDEFINED', warning.message);
    },
}

Rollup requires that your Babel configuration keeps ES6 module syntax intact.

JavaScript
{
  plugins: [
    babel({
      babelHelpers: 'bundled',
      babelrc: false,
    }),
    terser({ ecma: 6, module: true }),
  ],
}

SyntaxError: Unexpected token: punc (.)

Missing class properties transform.

  • @babel/plugin-proposal-class-properties

'default' is not exported by

  • 导入方式的问题
  • commonjs 问题
    • 加插件 @rollup/plugin-commonjs
  • 出现问题的包
    • classnames
TypeScript
// 这样不会使用 default
// TS 中的 allowSyntheticDefaultImports 参数
import * as Abc from './abc';

xxx.default is not a function

  • 一般是 commonjs 的问题

可以手动添加命名导出

JavaScript
commonjs({
  include: 'node_modules/**',
  // 新版本插件会自带处理,没有了该参数
  namedExports: {
    'node_modules/@emotion/memoize/dist/memoize.cjs.js': ['memoize'],
  },
});

lodash 没能 剔除/tree shake

使用 lodash-es,不要使用 lodash

  • lodash 是 cjs
  • lodash-es 是 esm

angularCompilerOptions

json
{
  "fullTemplateTypeCheck": true,
  "preserveWhitespaces": true
}

rollup.config.ts

  1. 使用插件
tsconfig.json
{
  "include": ["src", "rollup.config.ts"]
}
bash
rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript
# 等同于
rollup --config rollup.config.ts --configPlugin typescript
  1. 使用 cjs 转
rollup.config.js
require('ts-node').register({
  compilerOptions: {
    esModuleInterop: true,
  },
});

module.exports = require('./rollup.config.ts');

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

其他外链3 条
最近更新commit 77dd6df编辑