module.exports = {
externals: {
jquery: 'jQuery',
swiper: 'Swiper'
},
plugins: [
new webpack.ProvidePlugin({
'window.jQuery': 'jquery',
'window.$': 'jquery',
jQuery: 'jquery',
$: 'jquery',
'window.Swiper': 'swiper',
Swiper: 'swiper',
}),
new HtmlWebpackPlugin({}), // manage your HTML file
new HtmlWebpackExternalsPlugin({ // optional plugin: inject cdn
externals: [
{
module: 'jquery',
entry: 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js',
global: 'jQuery',
},
{
module: 'swiper',
entry: 'https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/js/swiper.js',
global: 'Swiper',
},
],
}),
],
}
const arr = [{name: "one", q: 5},{name: "one", q: 3},{name: "two", q: 1},{name: "two", q: 6},{name: "three", q: 10}]
const result = arr.reduce((acc, obj) => {
let index = acc.findIndex((elm) => {return elm.name == obj.name});
if(index == -1){ return acc.concat(Object.assign({}, obj) };
acc[index]['q'] += obj.q;
return acc
}, [])