Code Monkey home page Code Monkey logo

parcel-plugin-gas-imports's Introduction

parcel-plugin-gas-imports

Version License: MIT Twitter: VladoDev

๐Ÿ”ฅ Parcel plugin that enables bundling of Google App Script HTML.

๐Ÿ“š Introduction

If you've ever developed an add-on for Google's Office Suite with Google Apps Script, then you'll know how inefficient it is to develop your add-on's UI. This is because Google's Apps Script supports only .gs and .html files. If you want to use CSS and JS, the only option is to create an HTML file and wrap your CSS code inside <style> tag or your JS inside <script> tag and include it in your UI using scriptlets.

This approach has serious flaws. Parcel (nor any other modern JS bundler for that matter), doesn't recognize scriptlets <?!= ?>. Because of this, it won't apply any code transformation to those files and won't bundle them.

Why is this approach bad?

  • ๐Ÿšซ CSS not prefixed (The UI breaks on some browsers)
  • ๐Ÿšซ JS not transpiled (Usage of modern JS not possible)
  • ๐Ÿšซ Code can't be split in modules
  • ๐Ÿ’ฃ Large file sizes (Code not minified)

๐Ÿ“ฆ Installation

# Installs the plugin and saves it as a development dependency
npm i parcel-plugin-gas-imports -D

โ˜๏ธ Usage

The plugin allows you to include your JS and CSS just like you would normally do it in HTML:

# Example add-on UI files
src
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ style.css
โ””โ”€โ”€ script.js

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="style.css" />
  </head>

  <body>
    <h1>Google Apps Script Sidebar</h1>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="script.js"></script>
  </body>
</html>

๐Ÿš€ Build

parcel build src/index.html

# Fully optimized project ready for deployment
dist
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ style.e308ff8e.css.html
โ””โ”€โ”€ script.75da7f30.js.html

โ„น๏ธ NOTE: If you want to prevent this plugin from running in certain cases you can set PARCEL_PLUGIN_GAS_IMPORTS=false environment variable.

โœจ Run tests

The plugin uses Jest for running tests.

Jest will execute all .test.js files in the test folder.

npm test

๐Ÿ‘จ Author

Vladimir Mikulic

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!

๐Ÿ“ License

This project is licensed under MIT license.

๐Ÿ‘จโ€๐Ÿš€ Show your support

Give a โญ๏ธ if this project helped you!

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.