Rollupjs:忽略代码行
Rollupjs: Ignore lines of code
我的一个 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 时,我收到 "unexpected token" 错误。有没有办法告诉 rollup 忽略(只是把它放在输出文件中)一些代码行?
或者是否有 other/better 方法来处理 RollupJS 中的 lodash 模板语法?
我只想将上面的代码片段放在我的最终输出中!
我使用 rollup-plugin-replace plugin 修复了它。
在我的 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 文件正在使用 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 时,我收到 "unexpected token" 错误。有没有办法告诉 rollup 忽略(只是把它放在输出文件中)一些代码行?
或者是否有 other/better 方法来处理 RollupJS 中的 lodash 模板语法?
我只想将上面的代码片段放在我的最终输出中!
我使用 rollup-plugin-replace plugin 修复了它。
在我的 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) %>');
这正是我需要的!