diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index 0b9f2afda..bcaef6964 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -27,6 +27,8 @@ const escapeRegExp = str => { return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); }; +const avoidInline = em => em && em.getConfig('avoidInlineStyle'); + const Component = Backbone.Model.extend(Styleable).extend( { defaults: { @@ -363,9 +365,21 @@ const Component = Backbone.Model.extend(Styleable).extend( this.get('classes').each(cls => classes.push(cls.get('name'))); classes.length && (attributes.class = classes.join(' ')); - // If the rule is setted we need an ID attached to the component - if (!has(attributes, 'id') && sm && sm.get(id, sm.Selector.TYPE_ID)) { - attributes.id = this.getId(); + // Check if we need an ID on the component + if (!has(attributes, 'id')) { + let hasStyle; + + // If we don't rely on inline styling we have to check + // for the ID selector + if (avoidInline(em)) { + hasStyle = sm && sm.get(id, sm.Selector.TYPE_ID); + } else if (!isEmpty(this.getStyle())) { + hasStyle = 1; + } + + if (hasStyle) { + attributes.id = this.getId(); + } } return attributes; diff --git a/webpack.config.js b/webpack.config.js index c5f390d3a..504714f34 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -9,8 +9,8 @@ module.exports = env => { const name = pkg.name; const isProd = env === 'prod'; const output = { - path: path.join(__dirname, 'dist'), - filename: 'grapes.min.js', + path: path.join(__dirname), + filename: 'dist/grapes.min.js', library: name, libraryTarget: 'umd', }; @@ -21,7 +21,7 @@ module.exports = env => { new webpack.BannerPlugin(`${name} - ${pkg.version}`), ]; } else if (env === 'dev') { - output.filename = 'grapes.js'; + output.filename = 'dist/grapes.js'; } else { const index = 'index.html'; const indexDev = `_${index}`;