Search code examples
javascriptpolymerpolymer-1.0es6-modules

How to import javascript function with use of ES6 to Polymer 1.0 component?


I am using Polymer 1.0 and I would like to make my code modular with use of ES6. My idea is to create a few different files with function definitions which I would import to the .html file containing my polymer component definition where I could call them.

I tried to put the import statement into both created and attached polymer functions, but neither works.

Is that what I am trying even possible? If yes, then where should i put my import statement?


Solution

  • Polymer v1 imports components was in the html

    Example

    <link rel="import" href="../polymer.html">
    <link rel="import" href="../bower_components/polymer/polymer-element.html">
    

    so you could use webpack now for that and add all your imports in the same file like

    /* src/index.js */
    
    import './polymer';
    import './my-element.html';
    

    Put this file as an entry for webpack then it will take of all your imports to generate a single HTML file that you will link in your application.