Git Product home page Git Product logo

vite-javascript-webflow's People

Contributors

armandsalle avatar dannymout avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vite-javascript-webflow's Issues

Better way to handle environment

Hi, and first of all, thank you for your work !

I helped a friend of mine to setup this template andI noticed a small problem with the way you manage the different environments :
Actually, when you're on the production build, you first try to fetch localhost, and if it fails, you then try to fetch the correct build deployed on Netlify. To me, this is a problem because you have to wait for the localhost request to time out before getting the correct bundle (which can be up to 4 seconds !).

What I suggest would be to have two environements files (dev and prod) with the same variables declared but with the correct values according to the env (the main.js absolute urls) . You would then use the dev env file by default when developing, and swap it with the prod env file on build time, with the help of yarn build.

Of course, instead of files, you could just use a variable framed by an if :

let url;
if(prod){
  url = env.prod.url
}
else{
  url = env.dev.url
}

What do you think ?

Loading separate scripts for each page?

I'm newer to JS build tools/modules. Would I need to create separate modules for each page of my Webflow project?

My first thought is to call a function in main.js, depending on the current path.

Cannot use import statement outside a module?

I've been trying to implement this but am having a problem when bringing the code through from Netlify. It gives me the error

Uncaught SyntaxError: Cannot use import statement outside a module

Which reading the code I'm presuming is because dev mode is being set to false for production and the script is being loaded not as a module, so it doesn't like an import being in the code. What am I doing wrong? Also I notice that vite is loaded locally but not in production, is this right?

Code is here

(function () {
    const LOCALHOST_URL = [
    	'http://localhost:3000/@vite/client',
      'http://localhost:3000/src/homepage.js',
    ]
    const PROD_URL = ['https://buttermilk-tg.netlify.app/homepage.js']
    
function createScripts(arr, isDevMode) {
      return arr.map(function (url) {
        const s = document.createElement('script')
        s.src = url

        if (isDevMode) {
          s.type = 'module'
        }

        return s
      })
    }

    function insertScript(scriptArr) {
      scriptArr.forEach(function (script) {
        document.body.appendChild(script)
      })
    }

    const localhostScripts = createScripts(LOCALHOST_URL, true)
    const prodScripts = createScripts(PROD_URL, false)

    let choosedScripts = null

    fetch(LOCALHOST_URL[0], {})
      .then(() => {
        choosedScripts = localhostScripts
      })
      .catch((e) => {
        choosedScripts = prodScripts
        console.error(e)
      })
      .finally(() => {
        if (choosedScripts) {
          insertScript(choosedScripts)

          return
        }

        console.error('something went wrong, no scripts loaded')
      })
  })()

Blocked by CORS policy

Hi,
First of all, thank you very much for your work.
I have an issue with the netlify link. When I work locally with http://localhost:3000... everything works. I publish on netlify and change my script with that of netlify but I have a loading error. The script don't load with this error in the console : has been blocked by CORS policy: No 'Access-Control-Allow-Origin'. Do you know how to resolve this problem ?

Can't deploy with Netlify

Hey,

First of all, thanks a lot for your work. I'm using your template for a few projects and it's been very helpful.
I'm encountering a new issue when I'm deploying my website with Netlify (it was working perfectly until now):

error An unexpected error occurred: "Invalid value type 100:0 in /opt/build/repo/yarn.lock".

Do you have any idea of where it could come from?

Thanks a lot.

Prevent cache on prod

Hello Armand,

Sometimes, clients, project manager, users... has cached the dist js file generated.

I made this :

const d = new Date();
let seconds = d.getSeconds();
const PROD_URL = ['my_dist_url.js?'+ seconds]

What do you think ?

Runing into an issue on a clean vs code build

im running into this error message when the second i start the local server

Plugin: vite:eslint
 File: C:/Users/X/Documents/GitHub/Mariam-development/src/main.js
     at formatError (C:\Users\X\Documents\GitHub\Mariam-development\node_modules\vite\dist\node\chunks\dep-f5552faa.js:36769:46)
     at TransformContext.error (C:\Users\X\Documents\GitHub\Mariam-development\node_modules\vite\dist\node\chunks\dep-f5552faa.js:36765:19)
     at TransformContext.transform (C:\Users\X\Documents\GitHub\Mariam-development\node_modules\vite-plugin-eslint\dist\index.js:87:14)
     at async Object.transform (C:\Users\X\Documents\GitHub\Mariam-development\node_modules\vite\dist\node\chunks\dep-f5552faa.js:36985:30)
     at async doTransform (C:\Users\X\Documents\GitHub\Mariam-development\node_modules\vite\dist\node\chunks\dep-f5552faa.js:52060:29) (x6)
22:20:12 [vite] Internal server error: 
C:\Users\X\Documents\GitHub\Mariam-development\src\main.js
 1:51  error  Delete `␍`  prettier/prettier
 2:49  error  Delete `␍`  prettier/prettier
 3:28  error  Delete `␍`  prettier/prettier
 4:1   error  Delete `␍`  prettier/prettier
 5:47  error  Delete `␍`  prettier/prettier
 6:1   error  Delete `␍`  prettier/prettier
 7:14  error  Delete `␍`  prettier/prettier
 8:15  error  Delete `␍`  prettier/prettier

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.