Code Monkey home page Code Monkey logo

htmlimport2esmodule's Introduction

HTML Import to ES Module

Regex file parser to find and insert HTML imports into JS files.

This checks for JS files with matching HTML (for the code behind pattern) then just looks for HTML files.

Then this:

  • Tries to parse any JS from <script> tags in the HTML.
  • Looks for the static get is() property Polymer 2 uses to find the <dom-module>.
  • Finds the <template> in the relevant <dom-module>.
  • Extracts any scripts nested inside the template.
  • Extracts any <style> content into a const
  • CSS includes are included as explicit variables - the files themselves need to be converted manually.
  • HTML import directives are converted to ES Modules.
  • Polymer.Element is replaced by PolymerElement.
  • HTML template inserted as a literal string in the JS file.
  • JS file writtent to disk.
  • HTML file deleted.

Caveats

This is very much utlity code, with most corner cases just crashing. Expect bugs.

Dependencies are assumed to be in a library directory, and the name of this directory is used to find/replace dependencies references. This is a very quick and dirty way to do this - if you want to use this in your own application you will either have to use the same pattern or write the relative link checking code yourself.

Why not use the offical polymer-modulizer?

Because it doesn't work. Specifically:

This doesn't aim to do all the complex parsing of JS that the modualizer aspires to - I just want to make the same pattern changes to a few hundred HTML import components.

htmlimport2esmodule's People

Contributors

keithhenry avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.