Rollup FAQ
约 1 分钟阅读
标签:FAQ
this has been rewritten to undefined
- 配合 typescript 会出现,不影响使用,但很烦
忽略该错误
{
onwarn(warning) {
if (warning.code === 'THIS_IS_UNDEFINED') {
return;
}
console.warn('THIS_IS_UNDEFINED', warning.message);
},
}- this-is-undefined链接rollupjs.org/guide/en目的/核心 - 并不是要达到所有 - 需要权衡 · 垂直切分前端 · 技术无关 - 可混合多种框架 · 团队切分 - 独立 · 外部依赖共享 - React - Import Map · 独立部署 - 能部署某个组件或页面 · 附加 · SSR 支持 - 按照路由切分是可能的笔记:微前端
Rollup requires that your Babel configuration keeps ES6 module syntax intact.
{
plugins: [
babel({
babelHelpers: 'bundled',
babelrc: false,
}),
terser({ ecma: 6, module: true }),
],
}SyntaxError: Unexpected token: punc (.)
- Optional chaining
- 调整 transpile 或者 ts 的 target
Missing class properties transform.
@babel/plugin-proposal-class-properties
'default' is not exported by
- 导入方式的问题
- commonjs 问题
- 加插件 @rollup/plugin-commonjs
- 出现问题的包
- classnames
// 这样不会使用 default
// TS 中的 allowSyntheticDefaultImports 参数
import * as Abc from './abc';xxx.default is not a function
- 一般是 commonjs 的问题
可以手动添加命名导出
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
{
"fullTemplateTypeCheck": true,
"preserveWhitespaces": true
}rollup.config.ts
- 使用插件
{
"include": ["src", "rollup.config.ts"]
}rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript
# 等同于
rollup --config rollup.config.ts --configPlugin typescript- 使用 cjs 转
require('ts-node').register({
compilerOptions: {
esModuleInterop: true,
},
});
module.exports = require('./rollup.config.ts');关联信息
反向链接、本文链接的其他页面和外部资料。
参考资料
其他外链3 条
- angular.io/guide/angular-compiler-optionsangular.io/guide/angular-compiler-options
- developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chainingdeveloper.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
- rollupjs.org/guide/enrollupjs.org/guide/en