The following is a small webpack config change to have the ES6:
for (let item of collection)
Converted to the ES5:
for (let i = 0, item; i < collection.length | (item = collection[i]); i++)
-
Run
npm install --save string-replace-webpack-plugin
-
Add the following to your webpack.config.js file: (below the babel-loader, so that ours runs before it (yes, last runs first))
var StringReplacePlugin = require("string-replace-webpack-plugin");
//module.exports = {
// module: {
// loaders: [
{
test: /(\.js|\.jsx)$/,
loader: StringReplacePlugin.replace({replacements: [
{
pattern: /for \((\w+) (\w+) of ([A-Za-z0-9_.]+)\)/g,
replacement: function(match, varType, varName, listName, offset, string) {
return `for (let i = 0, ${varName}; i < ${listName}.length | (${varName} = ${listName}[i]); i++)`;
}
}
]})
}
// ...