I have a project where I'm using webpack2 and ES6 transpiled with babel. However I noticed that the resulting code from underscore-template-loader stays ES6 and is not transpiled. How do i update my webpack.config.js to transpile the resulting template result?
My current webpack.config.js:
const path = require('path');
module.exports = {
entry: 'app',
module: {
loaders: [
{
test: /\.html$/,
loader: 'underscore-template-loader',
query: {
engine: 'underscore',
prependFilenameComment: __dirname,
},
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: [
'es2015',
'es2016',
'es2017',
'stage-3',
],
},
},
],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
sourceMapFilename: '[file].map',
},
resolve: {
modules: [
path.join(__dirname, 'src'),
'node_modules',
],
},
devtool: 'source-map',
plugins: [],
};
An example arrow function in entry
_.forEach([1,2,3], (e) => {console.log(e);});
An example template:
<% _.forEach(test, (e) => { %>
<p>From template <%- e %></p>
<% }); %>
From the result:
_.forEach(test, (e) => { // not transpiled :(
__p+='\n <p>From template '+
((__t=( e ))==null?'':_.escape(__t))+
'</p>\n';
});
...
_underscore2.default.forEach([1, 2, 3], function (e) { // transpiled
console.log(e);
});
I have noticed when researching a possible solution that there are many template packages that might be compatible with underscore templates as well. If there are solutions using a different and compatible library I'm willing to switch.