cant deploy vue app in docker with parcel - vue.js

Not able to load vue in docker container, using parcel.
Vue is not loaded, and vue devtools cant find vue. All files seems to be in devtools/sources.
Its working outside of docker with npm run dev.
JS error:
Uncaught TypeError: Cannot read property 'props' of undefined
at vue.common.prod.js:6
Dockerfile:
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package.json /app
RUN apk add --update npm
RUN apk add util-linux
ENV FONTAWESOME_NPM_AUTH_TOKEN XXXXX
COPY .npmrc /app
RUN npm install
RUN npm audit fix
COPY src/. /app/src
COPY index.html /app
RUN npm run production
# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
package.json
{
"name": "myapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"alias": {
"vue": "/node_modules/vue/dist/vue.common.js"
},
"scripts": {
"dev": "parcel index.html",
"production": "parcel build index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#fortawesome/fontawesome-pro": "^5.15.1",
"axios": "^0.21.1",
"bootstrap": "^4.5.3",
"bootstrap-vue": "^2.21.2",
"faker": "^5.1.0",
"jquery": "^3.5.1",
"lodash": "^4.17.20",
"moment": "^2.29.1",
"vue": "^2.6.12",
"vue-hot-reload-api": "^2.3.4",
"vue-router": "^3.4.9"
},
"devDependencies": {
"#vue/component-compiler-utils": "^3.2.0",
"parcel-bundler": "^1.12.4",
"sass": "^1.32.2",
"vue-template-compiler": "^2.6.12"
}
}

I think I can probably get your dev server going.
I think parcel's default port is 1234. So you need to tell it to be on port 80. Also hot-reloading wont work unless you specify and expose the ws port that it
Change your package parcel run command like so.
{
...
"scripts": {
"dev": "parcel index.html -p 80 --hmr-port 33333",
},
}
Then add this to your Dockerfile
...
EXPOSE 33333
That should allow parcel to connect to the parcel dev server

Related

Different svelte variable value for npm run dev and npm run build

I'm developing a svelte+tailwind+PHP site with rollup.js. How can I set a variable in the svelte source files depending on if I'm running npm run dev or npm run build? I'd like the different builds to connect to different back-end servers.
This is my package.json in case that's relevant. I'm new to most of these tools, so please bear with me and correct me if I've misunderstood too much. After running npm run build, I run a script that scp's the build folder to the production server.
{
"name": "my-app",
"version": "1.0.0",
"scripts": {
"watch:tailwind": "postcss public/tailwind.css -o public/index.css -w",
"build:tailwind": "NODE_ENV=production postcss public/tailwind.css -o public/index.css",
"dev": "run-p autobuild watch:tailwind",
"build": "npm run build:tailwind && rollup -c",
"start": "sirv public --single --host",
"start:dev": "sirv public --single --dev",
"autobuild": "rollup -c -w"
},
"devDependencies": {
"#rollup/plugin-commonjs": "^16.0.0",
"#rollup/plugin-node-resolve": "^10.0.0",
"autoprefixer": "^10.0.4",
"d3-interpolate": "^2.0.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.1.10",
"postcss-cli": "^8.3.0",
"postcss-nested": "^5.0.1",
"postcss-reporter": "^7.0.2",
"rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.0.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"svelte": "^3.0.0",
"svelte-dnd-action": "^0.6.22",
"svelte-loading-spinners": "^0.1.1",
"tailwindcss": "^2.0.1"
},
"dependencies": {
"sirv-cli": "^1.0.0"
}
}
You can use #rollup/plugin-replace:
A Rollup plugin which replaces strings in files while bundling.
plugins: [
replace({
// alternatively, one could pass process.env.NODE_ENV or 'development` to stringify
'process.env.NODE_ENV': JSON.stringify('production')
})
]

How do you deploy api made with express in create react app

I have a simple api created with express.js. When ever i try to push to Heroku it get stuck at this point?
remote: [4/4] Building fresh packages...
remote: Done in 16.30s.
remote:
remote: -----> Build
remote: Running build (yarn)
remote: yarn run v1.22.4
remote: $ node server.js
remote: Server started on port 9000
I also see the same thing in heroku dashboard "View build progress"
here is my package.json
{
"name": "firebase-server",
"version": "1.0.0",
"main": "index.js",
"repository": "##########",
"author": "#######",
"license": "MIT",
"scripts": {
"start": "nodemon --ext js,graphql --ignore data/ server.js",
"build": "node server.js"
},
"dependencies": {
"#firebase/app": "^0.6.7",
"#firebase/component": "^0.1.15",
"apollo-server-express": "^2.15.1",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-jwt": "^6.0.0",
"firebase": "^7.15.5",
"graphql": "^15.3.0",
"jsonwebtoken": "^8.5.1",
"notarealdb": "^0.2.2"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}
the only thing i have in this project is my server.js. what am i missing or not doing. Basically i trying to deploy this to have a live API for my project. it is working locally but now i would like to have it working live on heroku.
With Heroku, the build script is used if you need to customize your build options (e.g. if you're using WebPack or TypeScript). The issue is that you're using a script called build, which you're expecting to start the application. It's running that script, as it promises to do, but since it's starting the application, it'll "hang forever" from your point of view.
If you change your scripts to this, I think this will solve your issues. Locally, you would use npm local for nodemon, and npm start would start the app on Heroku.
{
"scripts": {
"local": "nodemon --ext js,graphql --ignore data/ server.js",
"start": "node server.js"
},
}

npm script doesn't not launch karma test correctly

I'm using parcel to build my project on windows , and installed karma as my test runner. I hope when I changed my source code the parcel would rebuild the project and the karma would execute the test.so I add
"script": {
"dev-test": "parcel watch test/* --no-cache & karma start --auto-watch"
}
to my package.json.
The weird thing is when I run "npm run dev-test" , the parcel build the project but karma didn't excute any test, terminal shows "√ Built in 5.95s.", that's all I got.
I have to type the whole command "parcel watch test/* --no-cache & npx karma start --auto-watch" in my command line line(karma isn't installed globally so I have to add npx), it seems to be a workaround, but still have a bug("&" means parcel and karma runs simultaneously so karma would run the test several times when parcel is building project)
I don't want to type the whole command , I hope I can use npm script.
here's my package.json if it helps
{
"name": "custom-vue-component",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "parcel build test/* --no-cache --no-minify && karma start --single-run",
"dev-test": "parcel watch test/* --no-cache & karma start --auto-watch"
},
"repository": {
"type": "git",
},
"author": "me",
"license": "ISC",
"dependencies": {
"vue": "^2.6.11",
"vue-hot-reload-api": "^2.3.4"
},
"devDependencies": {
"#vue/component-compiler-utils": "^3.1.2",
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
"karma": "^5.0.9",
"karma-chai": "^0.1.0",
"karma-chai-spies": "^0.1.4",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",
"karma-sinon-chai": "^2.0.2",
"mocha": "^7.2.0",
"parcel-bundler": "^1.12.4",
"sass": "^1.26.7",
"sinon": "^9.0.2",
"sinon-chai": "^3.5.0",
"vue-template-compiler": "^2.6.11"
},
"alias": {
"vue": "./node_modules/vue/dist/vue.common.js"
}
}
and karma.conf.js
module.exports = function(config) {
config.set({
basePath: "",
frameworks: ["mocha", "sinon-chai"],
client: {
chai: {
includeStack: true,
},
},
files: ["dist/**/*.test.js", "dist/**/*.test.css"],
exclude: [],
preprocessors: {},
reporters: ["progress"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["ChromeHeadless"],
singleRun: false,
concurrency: Infinity,
});
}
If you are Windows user, you maybe meet this problem.
You can solve it by run parcel watch test/* --no-cache & karma start separately:
Open a git bush window and run npx parcel watch test/* --no-cache
Open another git bush window and run npx karma start

How to push to netlify in production mode [Nuxt JS]

I have my app created with nuxt js. I just want to push my app on Netlify.
So firstly i configure my deploy settings :
Repository on git
Base directory : Not set
Build command npm run build && npm run start
Publish directory .nuxt/dist
My app is build correctly but npm run start just launch on localhost:3000
I decided to modify config Host, I don't know if it's the best solution ?
{
"name": "app-nuxt",
"version": "1.0.0",
"description": "My remarkable Nuxt.js project",
"author": "wyllisMonteiro",
"private": true,
"config": {
"nuxt": {
"host": "https://mywebsite.com"
}
},
"scripts": {
"dev": "HOST=localhost PORT=3000 nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"test": "jest"
},
"dependencies": {
"#nuxtjs/axios": "^5.3.6",
"cookieparser": "^0.1.0",
"cross-env": "^5.2.0",
"js-cookie": "^2.2.0",
"nuxt": "^2.4.0",
"vee-validate": "^2.2.0",
"vuelidate": "^0.7.4",
"vuetify": "^1.5.5",
"vuetify-loader": "^1.2.1"
},
"devDependencies": {
"#vue/test-utils": "^1.0.0-beta.27",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^24.1.0",
"coffee-loader": "^0.9.0",
"coffeescript": "^2.4.0",
"jest": "^24.1.0",
"node-sass": "^4.11.0",
"nodemon": "^1.18.9",
"pug": "^2.0.3",
"pug-plain-loader": "^1.0.0",
"sass-loader": "^7.1.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"vue-jest": "^3.0.3"
}
}
I want to launch in localhost:3000 by executing npm run dev
AND https://mywebsite.com by executing npm run start
Can you tell me if there is some modifications in my package.json or in my deploy settings on Netlify
For anyone that stumbles across this in the future, the problem you're experiencing is due to a misunderstanding with what services Netlify offers.
Specifically, they are primarily a static site host, which means they will host your built files, and serve them for you. They will not run your server, which means nuxt start will not run.
Instead, you should be using nuxt generate to generate the static files of your app, and telling Netlify where the output folder is.
For example, the "build settings" on Netlify:
Repository github.com/example/example
Base directory Not set
Build command npm run generate
Publish directory dist
This will properly deploy a Nuxt app, assuming you haven't changed the default build folder. For clarification, the .nuxt folder contains both client and server files, and can only be used when running your own Nuxt server on an instance of some kind.
As it looks you need to tweak your deployment command. Go to Netlify and try changing it to npm install; npm run build. This should resolve the problem.

Deploying VueJS to GitHub Pages

I have followed the guide to deploy a VueJS app to GitHub pages step by step and it throws an error GET https://jedrekdomanski.github.io/bikeramp-front/ 404 ()
My repo (gh-pages branch): https://github.com/jedrekdomanski/bikeramp-front/tree/gh-pages
Website: https://jedrekdomanski.github.io/bikeramp-front/
script
https://cli.vuejs.org/guide/deployment.html#github-pages
#!/usr/bin/env sh
# abort on errors
set -e
# build
npm run build
# navigate into the build output directory
cd dist
# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME
git init
git add -A
git commit -m 'deploy'
# if you are deploying to https://<USERNAME>.github.io
# git push -f git#github.com:<USERNAME>/<USERNAME>.github.io.git master
# if you are deploying to https://<USERNAME>.github.io/<REPO>
git push -f git#github.com:jedrekdomanski/bikeramp-front.git master:gh-pages
cd -
vue.config.js
module.exports = {
baseUrl: process.env.NODE_ENV === 'production'
? '/bikeramp-front/'
: '/'
}
I am serving the app from gh-pages, like they said.
Source
Your GitHub Pages site is currently being built from the gh-pages branch.
What am I doing wrong?
package.json
{
...
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"axios": "^0.18.0",
"chart.js": "^2.7.3",
"vue": "^2.4.4",
"vue-chartjs": "^3.4.0",
"vue-router": "^3.0.1",
"vuex": "^3.0.0"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-2": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.11",
"file-loader": "^1.1.4",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
}
Maybe try to set baseUrl to full path instead of relative path, since there is limitations for relative path
Refer: https://cli.vuejs.org/config/#publicpath
Update:
Interesting that I notice after switching to full path, it works, then when switch back to relative path, it seems still working.
Here is how I deployed my Vuejs App to a github page:
I add a new file in the root project (next to package.json, ...): vue.config.js
I write inside:
module.exports = {
publicPath: "/something/",
outputDir: "docs",
};
Such that your url will be:
name.github.io/something/
the "docs" gives the output Folder for the npm run build because Github allows you just to choose between /(root) and /docs for the GitHub Page. So in this case on GitHub in the Settings of your project, go to Pages and for Source select /docs.
After that you have just to write following git order:
yourProject(main)$ npm run build
git add .
git status (to be sure)
git commit -am "your commentar"
git branch -M main (only if yourProject(master)is written instead of sfes(main) => GitHub changed master to main)
git push -u origin main