Vuetify design is broken when deployed on Heroku - css

Assumption
I am building a service with docker and Nuxt.js.. I am using Vuetyify for the user interface, but when deployed to Heroku, the CSS design is broken. Specifically, the alert width is not applied, there are blank spaces in the alert area, and other strange behavior. It works fine in the development environment. I have looked into it, but all I found is that the CSS loads differently in the development environment than in the production environment.
Is there any solution to this problem?
What we want to solve
I want to solve Vuetify design collapse on Heroku.
Code
package.json
{
"name": "app",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"export": "nuxt export",
"serve": "nuxt serve",
"generate": "nuxt generate",
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
"lint": "yarn lint:js",
"test": "jest"
},
"dependencies": {
"#nuxtjs/auth": "^4.9.1",
"#nuxtjs/axios": "^5.13.6",
"#vue/test-utils": "^1.3.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^27.4.6",
"core-js": "^3.9.1",
"jest": "^27.4.7",
"moment": "^2.29.1",
"nuxt": "^2.15.3",
"vue-jest": "^3.0.7"
},
"devDependencies": {
"#babel/core": "^7.16.12",
"#babel/preset-env": "^7.16.11",
"#nuxtjs/eslint-config": "^6.0.0",
"#nuxtjs/eslint-module": "^3.0.2",
"#nuxtjs/vuetify": "^1.11.3",
"babel-eslint": "^10.1.0",
"eslint": "^7.22.0",
"eslint-plugin-nuxt": "^2.0.0",
"eslint-plugin-vue": "^7.7.0"
}
}
nuxt.config.js
export default {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
ssr: false,
publicRuntimeConfig: {
APP_NAME: process.env.APP_NAME,
BOOK_URL: process.env.BOOK_URL,
AXIOS_POST: process.env.AXIOS_POST
},
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: 'KOUDOKU',
htmlAttrs: {
lang: 'ja'
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: '' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [
],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
・
・
・
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/eslint
'#nuxtjs/eslint-module',
// Doc: https://www.npmjs.com/package/#nuxtjs/vuetify
'#nuxtjs/vuetify'
],
moment: {
locales: ['ja']
},
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
// https://go.nuxtjs.dev/axios
'#nuxtjs/axios',
'#nuxtjs/auth'
],
// Axios module configuration: https://go.nuxtjs.dev/config-axios
・
・
・
// Added for anti-styling
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
extractCSS: true,
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.(css|scss)$/,
chunks: 'initial',
enforce: true
},
components: {
name: 'components',
test: /app\/components/,
chunks: 'all',
enforce: true
}
}
}
}
},
router: {
middleware: ['auth']
}
}
heroku.yml
setup:
config:
NODE_ENV: production
NPM_CONFIG_PRODUCTION: false
build:
docker:
web: Dockerfile
config:
WORKDIR: app
API_URL: "https://book-app-api-v1.herokuapp.com"
run:
web: yarn run start

Related

Webpack devServer set up on localhost opening the wrong local URL

I'm working on a WordPress plugin that will use a React App. I'm trying to get devServer to work with live reload. I need it to open http://localhost/shuffledink/builder in the browser. My current setup keeps opening http://localhost:8085 and shows all the files in assets/js when I run npm start. I commented out the port in my webpack config because I kept getting error:
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '127.0.0.1',
port: 80
I'm using XAMPP apache local server on port 80.
I also get this message in terminal:
[webpack-dev-server] Content not from webpack is served from 'C:\xampp\htdocs\shuffledink\wp-content\plugins\shuffled-ink-builder\assets\js' directory
Which is the correct path to my bundle files so I think that part is okay?
Here is my current config:
const path = require("path");
const webpack = require("webpack");
module.exports = {
mode: "development",
entry: {
main: "./src/index.js",
},
output: {
path: path.resolve(__dirname, "/assets/js"),
filename: "[name].bundle.js",
publicPath: "/assets/js/",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: ["#babel/preset-env"],
},
},
],
},
{
test: /\.s?css$/,
use: ["style-loader", "css-loader", "sass-loader"],
},
],
},
devServer: {
host: "localhost",
//port: 80,
static: path.join(__dirname, "/assets/js"),
liveReload: true,
open: true,
proxy: {
"/shuffledink/builder/": {
target: "http://localhost",
secure: false,
},
},
},
};
Here is my package.json:
{
"name": "Shuffled Ink",
"version": "1.0",
"private": true,
"description": "Shuffled Ink Card Bulder",
"scripts": {
"start": "webpack-dev-server --mode development",
"build": "webpack --mode production"
},
"devDependencies": {
"#babel/core": "^7.19.6",
"#babel/preset-env": "^7.19.4",
"#babel/preset-react": "^7.18.6",
"babel-loader": "^8.2.5",
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^6.7.1",
"mini-css-extract-plugin": "^2.6.1",
"style-loader": "^3.3.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
},
"dependencies": {
"#eastdesire/jscolor": "^2.5.1",
"#emotion/react": "^11.10.5",
"#emotion/styled": "^11.10.5",
"#mui/icons-material": "^5.11.0",
"#mui/material": "^5.11.1",
"#types/jest": "^29.2.4",
"#types/node": "^18.11.17",
"#types/react": "^18.0.26",
"#types/react-dom": "^18.0.9",
"fabric": "^5.2.4",
"fabric-history": "^1.7.0",
"node-sass": "^7.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.55.0",
"sass-loader": "^13.1.0",
"selectable.js": "^0.18.0",
"sortablejs": "^1.15.0",
"typescript": "^4.9.4"
}
}
I'm including my bundled JS file in my WordPress plugin like so:
function builder_scripts() {
if(get_query_var('custom_page')) {
wp_register_script('shuffled_ink_builder_scripts', plugins_url('assets/js/main.bundle.js', __FILE__), array(),null, true);
wp_enqueue_script('shuffled_ink_builder_scripts');
}
}
If the webpack-dev-server is opening the wrong URL, you can specify the correct URL by setting the public option in your webpack.config.js file:
module.exports = {
// ...
devServer: {
public: 'http://localhost:3000', // Specify the correct URL
// ...
}
};
Alternatively, you can start the webpack-dev-server with the --host option to specify the hostname to bind to:
webpack-dev-server --host 0.0.0.0
This should resolve the issue of the webpack-dev-server opening the wrong URL.

vueuse composables does not work in lib mode vite (vue 3)

I am trying build a vue 3 components library. Everything works fine. However I realized that the vueuse composables do not work when I try to use the library. This my first time writing a library. Is there any wrong with my code? Is there anything extra I need to do?. this my code, package.json and vite.config.ts. Any help will be much appreciated.
// code
setup(props, { slots }) {
const isLargeScreen = useMediaQuery("(min-width: 1024px)");
watch(
isLargeScreen,
(val) => {
console.log(val) //does not work;
}
);
return ()=><div>Hello world</div>
}
//package.json
{
"name": "my-lib",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview"
},
"dependencies": {
"#popperjs/core": "^2.11.5",
"#vitejs/plugin-vue-jsx": "^2.0.0",
"#vueuse/core": "^8.9.4",
"vue": "^3.2.37"
},
"devDependencies": {
"#vitejs/plugin-vue": "^3.0.0",
"typescript": "^4.6.4",
"vite": "^3.0.0",
"vite-plugin-dts": "^1.3.0",
"vite-plugin-windicss": "^1.8.7",
"vue-tsc": "^0.38.4",
"windicss": "^3.5.6"
},
"files": [
"dist"
],
"module": "./dist/my-lib.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/my-lib.mjs"
},
"./dist/style.css": "./dist/style.css"
}
}
// vite.config.ts
import { defineConfig } from "vite";
import { fileURLToPath, URL } from "url";
import { resolve } from "path";
import vue from "#vitejs/plugin-vue";
import dts from "vite-plugin-dts";
import WindiCSS from "vite-plugin-windicss";
import vueJsx from "#vitejs/plugin-vue-jsx";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
WindiCSS(),
vueJsx({}),
dts({
insertTypesEntry: true,
}),
],
esbuild: {
jsxFactory: "h",
jsxFragment: "Fragment",
},
resolve: {
alias: {
"#": fileURLToPath(new URL("./src", import.meta.url)),
},
},
build: {
lib: {
entry: resolve(__dirname, "src/main.ts"),
name: "MyLib",
fileName: "my-lib",
},
rollupOptions: {
external: ["vue", "#vueuse/core"],
output: {
globals: {
vue: "Vue",
"#vueuse/core": "VueCore",
},
},
},
},
});

Semicolon or block expected error svelte with postcss

I have set up a project with snowpack for svelte in which I'm trying to use tailwind for styling, but using states like hover or focus results in vs code throwing the error
Semicolon or block is expected
If you expect this syntax to work, here are some suggestions:
If you use less/SCSS with `svelte-preprocess`, did you add `lang=\"scss\"`/`lang=\"less\"` to your `style` tag? If you use SCSS, it may be necessary to add the path to your NODE runtime to the setting `svelte.language-server.runtime`, or use `sass` instead of `node-sass`.
Did you setup a `svelte.config.js`?
See https://github.com/sveltejs/language-tools/tree/master/docs#using-with-preprocessors for more info.
One code example that is causing the problem is
<style lang="postcss">
button {
#apply py-2 px-6 rounded-lg shadow-md;
}
.hoverable {
#apply hover:opacity-90;
}
</style>
This is the package.json
{
"scripts": {
"start": "run-p routify snp",
"build": "routify -b && routify export && snowpack build",
"test": "web-test-runner \"src/**/*.test.ts\"",
"routify": "routify",
"snp": "snowpack dev"
},
"dependencies": {
"#snowpack/plugin-run-script": "^2.3.0",
"postcss-import": "^14.0.2",
"svelte": "^3.37.0"
},
"devDependencies": {
"#roxi/routify": "^2.18.3",
"#snowpack/plugin-dotenv": "^2.2.0",
"#snowpack/plugin-postcss": "^1.4.3",
"#snowpack/plugin-svelte": "^3.6.1",
"#snowpack/plugin-typescript": "^1.2.1",
"#snowpack/web-test-runner-plugin": "^0.2.2",
"#testing-library/svelte": "^3.0.3",
"#tsconfig/svelte": "^1.0.10",
"#types/chai": "^4.2.17",
"#types/mocha": "^8.2.2",
"#types/snowpack-env": "^2.3.3",
"#web/test-runner": "^0.13.3",
"autoprefixer": "^10.4.0",
"chai": "^4.3.4",
"concurrently": "^6.4.0",
"cross-env": "^7.0.3",
"npm-run-all": "^4.1.5",
"postcss": "^8.3.11",
"postcss-cli": "^9.0.2",
"postcss-load-config": "^3.1.0",
"snowpack": "^3.8.7",
"svelte-preprocess": "^4.7.2",
"tailwindcss": "^2.2.19",
"typescript": "^4.3.4"
},
"routify": {
"extensions": "svelte,html,svx,md",
"dynamicImports": false,
"routifyDir": "src/.routify"
}
}
As you can see, I have installed svelte-preprocess which should be responsible for processing the postcss, as well as the other needed packages. The configuration for the project is as follows:
svelte.config.js
const sveltePreprocess = require("svelte-preprocess");
module.exports = {
preprocess: sveltePreprocess({
defaults: {
script: "typescript",
style: "postcss",
},
postcss: true,
}),
};
snowpack.config.js
/** #type {import("snowpack").SnowpackUserConfig } */
module.exports = {
mount: {
public: { url: "/", static: true },
src: { url: "/dist" },
},
plugins: [
"#snowpack/plugin-svelte",
"#snowpack/plugin-dotenv",
"#snowpack/plugin-typescript",
"#snowpack/plugin-postcss",
],
routes: [
/* Enable an SPA Fallback in development: */
{ match: "routes", src: ".*", dest: "/index.html" },
],
optimize: {
/* Example: Bundle your final build: */
// "bundle": true,
},
packageOptions: {
knownEntrypoints: ["#roxi/routify/runtime/buildRoutes"],
},
devOptions: {
/* ... */
},
buildOptions: {
/* ... */
},
};
postcss.config.js
module.exports = {
plugins: [
require("postcss-import"),
require("tailwindcss"),
require("autoprefixer"),
],
};
tailind.config.js
const production = process.env.NODE_ENV === "production";
module.exports = {
mode: "jit",
future: {
purgeLayersByDefault: true,
removeDeprecatedGapUtilities: true,
},
purge: { content: ["./src/**/*.svelte"], enabled: production },
darkMode: false, // or 'media' or 'class'
theme: {
extend: {/*...*/},
},
variants: {
extend: {},
},
plugins: [],
};
Do you have any idea if it's a configuration problem or is something related to the editor?

Gatsby Issue - on load and on refresh I am seeing a flicker of unstyled components

Issue - When I first load the page or I refresh the page, I get a flash of ugly un-styled features such as massive images, links go back to the custom styling of blue text with an underline, etc) before my own CSS applies.
Here is my package.json file -
{
"name": "gatsby-starter-hello-world",
"private": true,
"description": "A simplified bare-bones starter for Gatsby",
"version": "0.1.0",
"license": "0BSD",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
},
"dependencies": {
"#mdx-js/mdx": "^1.6.22",
"#mdx-js/react": "^1.6.22",
"babel-plugin-styled-components": "^1.12.0",
"gatsby": "^2.26.1",
"gatsby-image": "^2.7.0",
"gatsby-plugin-google-fonts": "^1.0.1",
"gatsby-plugin-manifest": "^2.9.0",
"gatsby-plugin-mdx": "^1.5.0",
"gatsby-plugin-sharp": "^2.9.1",
"gatsby-plugin-styled-components": "^3.5.0",
"gatsby-remark-images": "^3.6.0",
"gatsby-source-filesystem": "^2.6.1",
"gatsby-transformer-sharp": "^2.7.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-helmet": "^6.1.0",
"styled-components": "^5.2.1"
},
"devDependencies": {
"prettier": "2.1.2"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
}
}
Here is my gatsby-config file -
module.exports = {
siteMetadata: {
title: "Gatsby Project",
description: "",
image: "/logo.png",
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `pages`,
path: `${__dirname}/src/pages`,
},
},
{
resolve: `gatsby-plugin-styled-components`,
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `posts`,
path: `${__dirname}/src/posts`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
{
resolve: `gatsby-plugin-mdx`,
options: {
extensions: [`.mdx`, `.md`],
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-images`,
options: { maxWidth: 1200 },
},
],
},
},
{
resolve: `gatsby-plugin-google-fonts`,
options: {
fonts: [`roboto-mono`, `muli\:400,400i,700,700i`],
display: "swap",
},
},
{
resolve: `gatsby-plugin-manifest`,
options: {
icon: `src/images/logo.png`,
},
},
],
}
Am I missing a dependancy or is there a mistake in my config? Not sure..
Any suggestions would be much appreciated!
Usually, this kind of issue related to styled-components (known as FOUT, Flash of Unstyled Text) is solved by checking missing configurations but in your case, it seems that you have everything properly set in your gatsby-config.js and you have all packages installed.
One thing you can try is removing the gatsby-plugin-google-fonts since usually when dealing with font-face blocks the rendering while loading the JavaScript. According to https://github.com/typekit/webfontloader:
Using the Web Font Loader asynchronously avoids blocking your page
while loading the JavaScript. Be aware that if the script is used
asynchronously, the rest of the page might render before the Web Font
Loader is loaded and executed, which can cause a Flash of Unstyled
Text (FOUT).
If the issue is solved by removing this, you may need to find another way to add the fonts globally.
Credits: #LekoArts in this Spectrum topic

How to fix broken CSS on Netlify when using Gatsby?

I'm not sure where to begin troubleshooting a gatsby/netlify issue. When I run gatsby develop locally, my site looks one way, when I deploy to Netlify, it works another.
Where does one even begin fixing/troubleshooting this sort of thing?
My gatsby-config.js
const dotenv = require("dotenv")
dotenv.config({
path: `.env.${process.env.NODE_ENV}`,
})
module.exports = {
siteMetadata: {
title: `Berlin Music Map`,
description: "Find live music in Berlin",
author: `Kyle Pennell`,
},
plugins: [
'gatsby-plugin-sharp',
'gatsby-transformer-sharp',
`gatsby-plugin-react-helmet`,
// {
// resolve: "gatsby-plugin-remote-images",
// options: {
// nodeType: "item",
// imagePath: "thumbnail",
// name: 'optimized_thumbnail',
// }
// },
{
resolve: "gatsby-plugin-remote-images",
options: {
nodeType: "item",
imagePath: "soundcloud_artwork",
name: 'optimized_soundcloud_artwork',
}
},
{
// keep as first gatsby-source-filesystem plugin for gatsby image support
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/static/img`,
name: 'uploads',
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/src/pages`,
name: 'pages',
},
},
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
},
},
{
resolve: `gatsby-plugin-material-ui`,
options: {
theme: {
palette: {
primary: {
lighter: '#47B3C0',
light: '#397AB2',
main: '#005691',
dark: '#202E5F',
},
secondary: {
lighter: '#FFECC4',
light: '#FED969',
main: '#E7A700',
dark: '#C45527',
},
},
typography: {
html:{
fontSize:"14px"
},
h1: {
fontSize: "3.052em"
},
h2: {fontSize: "2.441em"},
h3: {fontSize: "1.953em"},
h4: {fontSize: "1.563em"},
h5: {fontSize: "1.25em"},
h6: {fontSize: "1.05em"},
fontFamily: '"Raleway", "Open Sans", "Arial", sans-serif',
useNextVariants: true,
},
},
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// 'gatsby-plugin-offline',
],
}
package.json
{
"name": "gatsby-starter-default",
"private": true,
"description": "A simple starter to get up and developing quickly with Gatsby",
"version": "0.1.0",
"author": "Kyle Mathews <mathews.kyle#gmail.com>",
"dependencies": {
"#material-ui/core": "^4.5.1",
"#material-ui/icons": "^4.5.1",
"#tippy.js/react": "^3.0.1",
"axios": "^0.19.0",
"dotenv": "^8.0.0",
"gatsby": "^2.17.7",
"gatsby-cli": "^2.8.8",
"gatsby-image": "^2.2.29",
"gatsby-plugin-layout": "^1.1.13",
"gatsby-plugin-manifest": "^2.2.25",
"gatsby-plugin-material-ui": "^2.1.6",
"gatsby-plugin-offline": "^2.0.25",
"gatsby-plugin-react-helmet": "^3.0.10",
"gatsby-plugin-remote-images": "^1.0.7",
"gatsby-plugin-sharp": "^2.2.32",
"gatsby-remark-copy-linked-files": "^2.0.11",
"gatsby-remark-images": "^3.0.1",
"gatsby-remark-relative-images": "^0.2.1",
"gatsby-source-filesystem": "^2.1.35",
"gatsby-transformer-remark": "^2.3.4",
"gatsby-transformer-sharp": "^2.1.9",
"google-map-react": "^1.1.5",
"lodash": "^4.17.15",
"memoize-one": "^4.0.2",
"moment": "^2.24.0",
"prop-types": "^15.7.2",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-fa": "^5.0.0",
"react-helmet": "^5.2.0",
"react-player": "^1.11.1",
"react-soundcloud-player": "^1.1.1",
"react-virtualized-auto-sizer": "^1.0.2",
"react-window": "^1.2.2",
"tippy.js": "^5.0.1"
},
"devDependencies": {
"prettier": "^1.16.4"
},
"keywords": [
"gatsby"
],
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write src/**/*.{js,jsx}",
"start": "npm run develop",
"serve": "gatsby serve",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\""
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-default"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
}
}
https://codesandbox.io/s/github/kpennell/berlinmusicmap/tree/master/?fontsize=14
The CSS injection order when doing gatsby build is a place to start. Material UI styles can get messed up when they are not injected first.
How to do it in the gatsby plugin:
https://www.gatsbyjs.org/packages/gatsby-plugin-material-ui/#advanced
From the MUI docs: https://material-ui.com/styles/advanced/#css-injection-order
Can you try to run gatsby build && gatsby serve on your local machine? Then go to localhost:9000 to see if your layout is all messed up.
Generally, it's good to check the built version of your Gatsby site by running this command. Especially since the new build time pricing of Netlify 😱
The issue might be independent of Netlify and related to Material UI.
Check this issue: https://github.com/mui-org/material-ui/issues/18197 you might find some useful information in it.
I (seemingly) solved this by literally copying what I had gatsby-browser.js to gatsby-ssr.js (wrapRootElement + wrapPageElement). I'm still not totally sure why this worked -- I'll need to read more about these in Gatsby's docs.
Dear frustrated/lost person from the future seeing wacky different CSS between gatsby develop and gatsby build ....if you're using React Context, try verbatim copying your wrapRootElement/wrapPageElement between the two files.

Resources