Babel plugin that will join strings and template strings in compilation time whenever it's possible.
You can use Array.proptotype.join
to join list of strings and template strings together.
In
const className = 'container';
const html = [
`<div class=${className}>`,
'<span>Hello World</span>',
'</div>',
].join('');
Out
const html = `<div class=${className}><span>Hello World</span></div>`;
Also, you can use +
to simply concat strings and template strings together.
In
const className = 'container';
const html =
`<div class=${className}>` +
'<span>Hello World</span>' +
'</div>';
Out
const html = `<div class=${className}><span>Hello World</span></div>`;
$ npm install babel-plugin-transform-string-join
.babelrc
{
"plugins": ["transform-string-join"]
}
$ babel --plugins transform-string-join script.js
require('babel-core').transform('code', {
plugins: ['transform-string-join']
});
MIT