I would like to run locally a Vue.js/System.js demo app I just got recently, never used System.js before (and I'll not...)
I only want to run this demo, before switching it to webpack...
There is no npm script (so no install, no run dev)
How should I run it to display in my local browser?
Anything to do before running? (there is no documentation on it..)
demo
app
components
About
App
..
index.js
routes
Home
...
index.js
style
main.css
assets
home
...
...
documentation
...
libs
favicon.ico
index.html
readme.html
UPDATE
Here is the system.config:
System.config({
defaultJSExtensions: true
, map: {
'app': './app'
, 'js': '/libs/js'
, 'style': '/libs/css'
, 'theme': '/app/theme'
, 'babel': '/libs/js/babel-core'
, 'components': '/app/components',
'routes': '/app/routes',
},
transpiler: 'babel'
, meta: {
'js/*.js': {
format: 'global'
}
}
});
System.import('/app/index.js');
And the index.html:
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="author" content="BelosTemas">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test template</title>
<link rel="shortcut icon" type="image/png" href="favicon.ico" />
<link rel="stylesheet" href="./app/style/main.css" id="theme-stylesheet">
</head>
<body>
<div id="app">
<app></app>
</div>
<!-- system -->
<script src="/libs/js/system.js"></script>
<script src="/app/system.config.js"></script>
</body>
</html>
UPDATE 2
I changed the script src paths in the index.html relative paths (src='./)
now the script file is located .. but it's not executed correctly, CORS related issue ..
Error:
system.js:5 Failed to load file:///app/index.js: Cross origin requests
are only supported for protocol schemes: http, data, chrome,
chrome-extension, https.
I solved it , installing a lightweight web server
npm install -g live-server
then in the console, going to my app directory, I just run it
live-server
default browser is open with http://localhost:8080
bonus : hot reloading !
Related
Just starting with vue.js. I am using Visual Studio Code, and have followed all the instructions for using VS Code with the Volar extension. I can see from the source files that the sample project includes a 'hello world' page (HelloWorld.vue). But when I run index.html I just get a blank screen , because of a CORS error (see below).
I haven't changed any code from the installed sample, so it appears that the vuejs.org instructions are not complete.
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app">
</div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
and main.js:
import { createApp } from 'vue'
import App from './App.vue'
import './assets/main.css'
createApp(App).mount('#app')
So what do I need to do to make use of the example .vue components?
The Chrome console shows a CORS problem:
Access to script at 'file:///C:/Users/quilk/Documents/testvue/main.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
To have an easy and simple time working with Vue, I recommend following the official steps:
npm init vue#latest
cd <your-project-name>
npm install
npm run dev
For CORS, you need to fix it on your backend/service dashboard. More details are available here.
I have a Vue (^2.6.10) application and want to build it to electron. I use "vue-cli-service build" and paste the created dist folder in my electron project but the html page only shows white, without errors.
My Vue main entry:
window.Api.Vue = {
start () {
window.app = new Vue({
el: '#app'
, i18n
, router
, render: h => h(App)
})
}
}
This builds correctly into the app.js file in the dist folder.
My dist/index.html file:
<!DOCTYPE html>
<html lang="">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<meta name=format-detection content="telephone=no">
<link rel=icon href=www/favicon.ico>
<title>Salesapp</title>
<link href=css/app.css rel=stylesheet>
<script type="module" defer="defer" src="app.js"></script>
</head>
<body>
<noscript><strong>We're sorry but salesapp doesn't work properly without JavaScript enabled. Please enable it to
continue.</strong></noscript>
<div id="app"></div>
</body>
</html>
I have tried the same approach successfully with other projects, but somehow this one doesn't work. Does anyone know why my html page is empty, and doen't return any errors?
These errors occur after the build:
Error from hosting in GitHub pages:
Failed to load resource: the server responded with a status of 404 () /e-library/js/app.af7a444d.js:1
Error from opening it locally:
Access to script at 'file:///D:/Office%20Files/Projects/eLibrary/e-library/dist/js/chunk-vendors.0aa8295f.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
But running on the server it works perfectly.
My index.html file:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" href="favicon.ico">
<title>e-library</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/#mdi/font#latest/css/materialdesignicons.min.css">
<script defer="defer" type="module" src="js/chunk-vendors.8ef93056.js"></script>
<script defer="defer" type="module" src="js/app.af7a444d.js"></script>
<link href="css/chunk-vendors.82c260bb.css" rel="stylesheet">
<link href="css/app.3dfcde27.css" rel="stylesheet">
<script defer="defer" src="js/chunk-vendors-legacy.8c436468.js" nomodule></script>
<script defer="defer" src="js/app-legacy.687726a0.js" nomodule></script>
</head>
<body><noscript><strong>We're sorry but e-library doesn't work properly without JavaScript enabled. Please enable it to
continue.</strong></noscript>
<div id="app"></div>
</body>
</html>
I tried publicPath:
module.exports = { publicPath: '', transpileDependencies: [ 'vuetify' ] }
Did I miss something?
I fixed it by adding this line of code in vue.config.js:
const {defineConfig} = require('#vue/cli-service')
module.exports = defineConfig({
publicPath: process.env.NODE_ENV === 'production'
? '/e-library/'
: '/'
I have a Vuejs app that I'm trying to serve via a Golang backend that will also serve the app's API.
When I build and run the Vuejs via "npm run build" and "serve -s dist" and go to the static server's location, everything loads up fine. But when I try to load it through the Golang backend, even though the index.html loads (as verified by checking the source in the browser), I just get a blank white page.
Is this approach not possible? Am I going about this all wrong?
Here is how I am serving the "dist" folder via Golang.
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(htmlFolder+"/dist/"))))
My index.html file:
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<link rel=icon href=/favicon.ico>
<title>TestApp</title>
<link href=/css/app.52c62e82.css rel=preload as=style>
<link href=/css/chunk-vendors.7724753e.css rel=preload as=style>
<link href=/js/app.9a3ab992.js rel=preload as=script>
<link href=/js/chunk-vendors.6808fe3a.js rel=preload as=script>
<link href=/css/chunk-vendors.7724753e.css rel=stylesheet>
<link href=/css/app.52c62e82.css rel=stylesheet>
</head>
<body>
<noscript>
<strong>We're sorry but TestApp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id=app></div>
<script src=/js/chunk-vendors.6808fe3a.js></script>
<script src=/js/app.9a3ab992.js></script>
</body>
</html>
Edit:
I also tried using gorilla/mux example here:
https://blog.questionable.services/article/vue-react-ember-server-golang/
And here is my "dist"'s folder structure.
press F12 on your browser and go to console tab to view the error
Turns out I just needed to empty my caches. I was using FN5 when refreshing assuming that that would reload it.
I setup my first elm project with parcel for automatic rebuild and hmr, however, hmr is not working when I edit .elm files. It works if I change anything on the html or js side. Any hints?
Just did
npm install -g parcel-bundler
parcel index.html
Followed this guide - https://parceljs.org/elm.html
package.json
{
"devDependencies": {
"elm-hot": "^1.0.1",
"node-elm-compiler": "^5.0.3"
},
"dependencies": {}
}
index.html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Photo Groove</title>
<link rel="stylesheet" href="http://elm-in-action.com/styles.css">
</head>
<body>
<div id="app"></div>
<script src="src/index.js"></script>
</body>
</html>
index.js
import { Elm } from './PhotoGroove.elm';
Elm.PhotoGroove.init({
node: document.getElementById('app')
});