Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lodash.template 生成的代码在严格模式下报错的解决办法 #5

Open
fisker opened this issue Sep 25, 2017 · 0 comments
Open

Comments

@fisker
Copy link
Owner

fisker commented Sep 25, 2017

使用 lodash-cli
lodash template 生成的js 文件 因为使用了 with 语句,会在严格模式下报错

可以使用 Function 来执行代码 就可以避免这个问题了

const templates = Function('return' + code /* 生成的代码 */)()

// 压缩版的js 可能需要 手动删除开头的;

参考 app.js

build 参数

lodash exports="none" \
 iife="(function(){%output%;return templates})()" \
 template=*.jst \
 -o complied.js

参考 build-template.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant