lodash - Rollupjs:忽略代码行
问题描述
我的 javascript 文件之一是使用 lodash 模板语法:
const deliveryClient = new DeliveryClient({
enablePreviewMode: <%= options.enablePreviewMode %>,
projectId: '<%= options.projectId %>',
previewApiKey: '<%= options.previewApiKey %>',
defaultLanguage: '<%= options.defaultLanguage %>',
enableAdvancedLogging: <%= options.enableAdvancedLogging %>,
baseUrl: '<%= options.baseUrl %>',
typeResolvers: typeResolvers
});
但是当我运行 rollup -c 时,我得到一个“意外令牌”错误。有没有办法告诉汇总忽略(只是把它放在输出文件中)一些代码行?
还是有其他/更好的方法来处理 RollupJS 中的 lodash 模板语法?
我只想将上面的代码片段放在我的最终输出中!
解决方案
我通过使用rollup-plugin-replace 插件修复了它。
在我的 javascript 中,我将代码更改为以下内容:
const deliveryClient = new DeliveryClient('KENTICOOPTIONS');
并在rollup.config.js
我添加了具有以下配置的插件:
replace({
include: 'lib/templates/plugin.template.js',
KENTICOOPTIONS: '<%= serialize(options) %>'
})
所以这给出了最终输出:
const deliveryClient = new DeliveryClient('<%= serialize(options) %>');
这正是我需要的!
推荐阅读
- javascript - 使用 jquery click 更改 HTML - 然后返回原始 HTML
- apache-spark - 如何从 PySpark DataFrame 的列中分离特定字符并使用它们形成一个新列?
- python - 在每组 Python 中进行优化
- html - 如何从botton重定向到页面?
- java - OpenNLP:无法访问 jarfile LemmatizerTrainerME
- excel - VBA:如何将 Cell.Address() 传递给可用的 sheet.range.select 格式,以便我可以将新值放入单元格
- python - 使用 argparse 将逗号分隔的多个整数值作为输入,并检查列表中是否存在这些值
- d3.js - D3 数据 join() 调用输入而不是更新
- css - 更改嵌套 div 中复选框的颜色
- ios - 从 iOS Objective-C 框架访问 Bundle 资源(字体、图像)