Rollupjs:忽略代码行

时间:2018-06-04 11:25:40

标签: 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
});

但是当我运行汇总-c时,我收到“意外令牌”错误。有没有办法告诉汇总忽略(只是把它放在输出文件中)一些代码行?

或者还有其他/更好的方法来处理RollupJS中的lodash模板语法吗?

我只想将上面的代码片段放在我的最终输出中!

1 个答案:

答案 0 :(得分:0)

我使用rollup-plugin-replace插件(https://github.com/rollup/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) %>');

这正是我所需要的!

相关问题