我的项目有一个简单的webpack设置,它在前端使用ejs-templating:
jump(heldtime, waittime
当我使用<ul>
<% for (let station of stations) { %>
<li>
<strong><%= station.name %></strong>
<br/>
Coach Code: <%= station.nationalcoachcode %><br/>
Distance: <%= (station.distance / 1000 ).toFixed(1) %> km
</li>
<% } %>
</ul>
投放它或使用webpack-dev-server
构建它时效果很好,但是当我尝试使用webpack
进行缩小构建时,它无法处理for-of循环再次给我以下错误:
webpack -p
这是我的ERROR in app.js from UglifyJs
SyntaxError: Unexpected token name «station», expected punc «;» [./~/ejs-loader!./src/app/stations.tmpl.ejs:7,0]
:
webpack.config.js
[编辑]:我已经尝试过首先通过babel运行ejs模板,但这并没有解决它。
答案 0 :(得分:1)
我的英语不好:(看看代码:
module: {
preLoaders: [
{
test: /\.ejs$/, loader: 'ejs-compiled'
}
],
loaders: [
{
test: /\.e?js$/, // <-- look!
exclude: /node_modules/,
loader: "babel-loader",
query: {
presets: ['es2015']
}
}
]
},
'ejs-compiled-loader': {
htmlmin: true,
htmlminOptions: {
removeComments: true
},
_with: false // <-- important!!!
}
在EJS中
<% var {station} = locals; %>
<ul>
<% for (let station of stations) { %>
<li>
<strong><%= station.name %></strong>
<br/>
Coach Code: <%= station.nationalcoachcode %><br/>
Distance: <%= (station.distance / 1000 ).toFixed(1) %> km
</li>
<% } %>
</ul>
我希望有帮助...