title: Polymer build with custom babel plugins?
body: <p>We'd like to be able to add custom functionality to <code>polymer build</code> and <code>polymer serve</code> by configuring custom babel plugins.</p>
  
  <p>For example, since polymer-cli uses babel internally, we would add a <code>babel.config.js</code> file to our workspace/project-root, e.g.:</p>
  
  <pre><code>module.exports = function (api) {
  
    api.cache(true);
  
  
    const presets = [ ];
    const plugins = [
   "@babel/plugin-proposal-optional-chaining"
   ];
  
  
    return {
      presets,
      plugins
    };
  }
  </code></pre>
  
  <p>...and then we could serve or build our project with support for optional-chaining, etc This would allow us to do all sorts of things by writing additional babel plugins to handle stuff like minification inside template HTML strings...</p>
  
  <p>Unfortunately, this doesn't currently work. <code>polymer-build</code> seems to load the configuration (due to its use of babel/core?), but <code>polymer-analyze</code> doesn't. An error is generated in the build-optimization step performed by polymer-analyze as soon as it encounters optional-chaining syntax in our source:</p>
  
  <pre><code>error:  Error: Unable to get document file:///.../somefile.js: This experimental syntax requires enabling the parser plugin:  
  'optionalChaining' (423:6)  
      at BuildAnalyzer.&lt;anonymous&gt; (/usr/local/share/.config/yarn/global/node_modules/polymer-build/lib/analyzer.js:342:23)
      at Generator.next (&lt;anonymous&gt;)  
      at fulfilled  (/usr/local/share/.config/yarn/global/node_modules/polymer-build/lib/analyzer.js:17:58)
      at process._tickCallback (internal/process/next_tick.js:68:7)
  </code></pre>
  
  <p><code>polymer serve</code> also generates an error:</p>
  
  <pre><code>Error { SyntaxError: This experimental syntax requires enabling the parser plugin: 'optionalChaining' (423:6)
      at Parser.raise (/usr/local/share/.config/yarn/global/node_modules/babylon/lib/index.js:776:15)  
      at Parser.expectPlugin (/usr/local/share/.config/yarn/global/node_modules/babylon/lib/index.js:2084:18)  
  ...   
  pos: 13056,   loc: Position { line: 423, column: 6 },  
  missingPlugin: [ 'optionalChaining' ] }
  </code></pre>
  
  <p>In both cases, I've confirmed that the <code>babel.config.js</code> file <strong>is</strong> being loaded. But babel is included by several different packages used in polymer-cli, so my suspicion is that in some of them, babel is being used without (babel/core having loaded) configuration info.</p>
  
  <p>Can anyone involved with the polymer project confirm whether I'm correct in identifying the main issue? I'm looking into the possibility of contributing a fix/enhancement if the scope isn't too large.</p>
  
  <p>Thanks.</p>