Code Monkey home page Code Monkey logo

webflow-typescript-webpack's Introduction

webflow-webpack

This is a basic setup with Webpack and Typescript that you can use for your Webflow website. jQuery is already installed and declared as an external dependency. By default, Webpack bundles multiple files for better performances (one file by page to avoid heavy JS load on a page that doesn't need it), but you can change this in the webpack.config.js. I'm using Netlify to build and host my code because it's easy to use, free, and has serverless functions out of the box. Feel free to use your favorite CDN.

How to use with Webflow

โš ๏ธ if you are using Brave as a web browser or an ad blocker, you will need to disable it. Else it can block the fetching of the js files. โš ๏ธ

If you are developing the site and coding at the same time, you can just add a script tag on pages that need your code

<script src="http://localhost:9000/index.js"></script>

But if you only code and don't have access to the project you can use this code to check if there is a local dev server running on your machine and switch between production code hosted on Netlify or not. This code is not due to be used in production.

<script>
  const LOCALHOST_URL = 'http://localhost:9000/index.js'
  const PROD_URL = 'https://YOUR_DOMAIN.netlify.app/index.js'

  const s = document.createElement('script')

  fetch(LOCALHOST_URL, {
    mode: 'no-cors',
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
  })
    .then(() => {
      s.src = LOCALHOST_URL
    })
    .catch((e) => {
      s.src = PROD_URL
      console.error(e)
    })
    .finally(() => {
      document.body.appendChild(s)
    })
</script>

For a production-ready code, add a script tag with your production URL.

<script src="https://YOUR_DOMAIN.netlify.app/index.js"></script>

Building and running on localhost

This project is using yarn.

First, install dependencies:

yarn

To launch a local dev server:

yarn dev

To create a production build:

yarn build

webflow-typescript-webpack's People

Contributors

armandsalle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  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.