I'm working on a NextJS application with PurgeCSS. I have to restart the server every single time I change the classname of a component.
Here are my postcss.config.js:
plugins: [
[
'#fullhuman/postcss-purgecss',
{
content: [
'./src/pages/**/*.{js,jsx,ts,tsx}',
'./src/pages/*.{js,jsx,ts,tsx}',
'./src/components/**/*.{js,jsx,ts,tsx}',
'./src/containers/**/*.{js,jsx,ts,tsx}',
],
defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
safelist: ['html', 'body'],
enableDevPurge: false,
},
],
'postcss-preset-env',
],
};
My package.json dependencies:
"dependencies": {
"date-fns": "^2.29.3",
"next": "13.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.7.1",
"sass": "^1.57.1"
},
"devDependencies": {
"#fullhuman/postcss-purgecss": "^5.0.0",
"#types/node": "18.11.18",
"#types/react": "18.0.26",
"#types/react-dom": "18.0.10",
"#typescript-eslint/eslint-plugin": "5.48.0",
"#typescript-eslint/parser": "5.48.0",
"autoprefixer": "^10.4.13",
"eslint": "8.31.0",
"eslint-config-next": "13.1.1",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-next": "^0.0.0",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.3",
"lint-staged": "13.1.0",
"next-purge-css-modules": "1.1.0",
"postcss": "^8.4.20",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-preset-env": "^7.8.3",
"prettier": "^2.8.1",
"typescript": "4.9.4"
}
I'm using global styles, not module styles, and scss instead of css.
This is my _app.tsx:
import '../styles/Global.scss';
import type { AppProps } from 'next/app';
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
}
export default MyApp;
Say I have these two styles:
.bg-blue { background-color: blue; }
.bg-red { background-color: red; }
If I had bg-blue used on a div's className, and I change it to bg-red, its ruleset is missing from the stylesheet.
I'm assuming purgecss doesn't update the stylesheet and does only one purge on server start.
It's definitely not ideal, but I don't care if I can just disable the whole purge functionality. However, can't find a way for that either.
Any tips?
I'm struggling with configuring a project set with Vite4, Vue3.
App.vue should simply import a module defined in other min.js file,
but it isn't and showing an error "{module name} is not defined".
Glad to be know if there is anything I have missed.
Thank you in advance!
package.json
{
"name": "test-project",
"version": "0.0.3",
"scripts": {
"dev": "vite --host --port 3333",
"start:dev": "vite --port 80 --mode dev",
"start:prod": "vite --host --port 80 --mode production",
"build": "vite build",
"build:dev": "vite build --mode dev",
"build:prod": "vite build --mode production",
"serve": "vite preview --open",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore --fix src",
"format": "prettier . --write",
"test:unit": "jest"
},
"dependencies": {
"#babel/preset-env": "^7.16.5",
"#bundled-es-modules/axios": "^0.21.1",
"#datadog/browser-rum": "^4.15.0",
"#j-t-mcc/vue3-chartjs": "^1.2.0",
"#juggle/resize-observer": "^3.3.1",
"#popperjs/core": "^2.10.2",
"#rollup/plugin-commonjs": "^24.0.0",
"#rollup/plugin-node-resolve": "^15.0.1",
"#stomp/stompjs": "^6.1.2",
"chart.js": "^3.7.0",
"crypto-js": "^4.1.1",
"element-plus": "^1.2.0-beta.6",
"esbuild": "^0.14.5",
"file-saver": "^2.0.5",
"mitt": "^3.0.0",
"moment": "^2.29.1",
"moment-timezone": "^0.5.37",
"path": "^0.12.7",
"sockjs-client": "^1.5.2",
"swiper": "^7.4.1",
"vite-plugin-html": "^3.2.0",
"vue": "^3.2.16",
"vue-chart-3": "^3.0.4",
"vue-cookie-next": "^1.3.0",
"vue-router": "^4.0.12",
"vue-universal-modal": "^1.1.3",
"vue-zoomer": "^0.4.0-beta.2",
"vue3-lottie": "^2.1.0",
"vuex": "^4.0.2",
"webstomp-client": "^1.2.6",
"yup": "^0.32.11"
},
"devDependencies": {
"#types/jest": "^27.0.3",
"#vitejs/plugin-vue": "^4.0.0",
"#vue/test-utils": "^2.0.0-rc.17",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-vue": "^8.1.1",
"jest": "^26.6.3",
"prettier": "^2.5.0",
"sass": "^1.45.1",
"ts-jest": "^26.5.6",
"vite": "^4.0.0",
"vue-jest": "^5.0.0-alpha.10"
}
}
vite.config.js
import { defineConfig } from 'vite'
import vue from '#vitejs/plugin-vue'
import { splitVendorChunkPlugin } from "vite";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [splitVendorChunkPlugin(), vue()],
})
index.html (nothing should have been changed from default settings...)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
main.js
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import '../src/assets/js/no-working-logic.min.js'; <- this is problem
import 'element-plus/dist/index.css';
createApp(App).mount('#app')
App.vue (partial)
<script>
import {onMounted, ref} from 'vue';
export default {
setup() {
const password = ref("");
onMounted(() => {
try {
const passwordId = document.getElementById('password');
const passwordRandom = new KeypadSuit(pinRandom, {
--- some random logic here ---
// new Keypadsuit <- this Keypadsuit is defined in no-working-logic.min.js
} catch (e) {
alert(e)
}
});
return {
password
}
}
}
</script>
<template>
<el-form-item prop="password">
<el-input
id="password"
type="password"
placeholder="비밀번호"
v-model="password"
maxlength="4"
>
</el-input>
</el-form-item>
</template>
the problem is(as described on App.vue logic),
no-working-logic.min.js works well on other environments except these.
I have tried with some plugins avaliable on Vite and rollupOptions,
but it was not enough to declare and solve this error.
Should any other conditions/ additional codes be shared, please let me know! Thanks!
the problem that i don't know how to solve it is (TypeError: Cannot read properties of undefined (reading 'call')) basically i have no idea where it can be in the console i don't have thread only on the error page
this is what my app looks like
app/studio/[[...index]]/page.tsx
'use client'
import {NextStudio} from 'next-sanity/studio'
import config from '../../../sanity.config'
export default function StudioPage() {
// Supports the same props as `import {Studio} from 'sanity'`, `config` is required
return <NextStudio config={config} />
}
app/studio/[[...index]]/head.tsx
export {NextStudioHead} from 'next-sanity/studio/head'
import {NextStudioHead} from 'next-sanity/studio/head'
export default function CustomStudioHead() {
return (
<>
<NextStudioHead favicons={false} />
<link
rel="icon"
type="image/png"
sizes="32x32"
href="https://www.sanity.io/static/images/favicons/favicon-32x32.png"
/>
</>
)
}
app/studio/[[...index]]/head.tsx
'use client'
import config from '../../../sanity.config'
import NextStudioLoading from 'next-sanity/studio/loading'
export default function Loading() {
return <NextStudioLoading config={config} />
}
next.config.js
module.exports = {
reactStrictMode: true,
experimental:{
appDir: true
}
}
sanity.cli.ts
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: process.env.NEXT_PROJECT_ID,
dataset: 'production'
}
})
sanity.config.ts
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: process.env.NEXT_PROJECT_ID,
dataset: 'production'
}
})
package.json
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"#portabletext/react": "^2.0.0",
"#sanity/image-url": "^1.0.1",
"next": "latest",
"next-sanity": "^3.1.3",
"prop-types": "^15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"#sanity/vision": "^3.0.0",
"sanity": "^3.0.0",
"styled-components": "^5.2.0"
},
"devDependencies": {
"#sanity/eslint-config-studio": "^2.0.1",
"#types/node": "18.11.3",
"#types/react": "18.0.21",
"#types/react-dom": "18.0.6",
"autoprefixer": "^10.4.12",
"postcss": "^8.4.18",
"tailwindcss": "^3.2.1",
"typescript": "4.8.4"
}
}
I faced the same error and solve it by installing the canary version of next 13 "npm i next#13.0.8-canary.2"
I'm having an issue using pinia, Previously I used vuex on my project but I wanted to migrate to pinia to handle my store. So I think, I setup pinia properly. So I can run the serv of my application without issues. But here is what i get when i open the page (PS: The vue dev tools is not anymore detected):
Here is my file package.json:
{
"name": "ecomm-challenge",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^6.1.1",
"#fortawesome/free-regular-svg-icons": "^6.1.1",
"#fortawesome/free-solid-svg-icons": "^6.1.1",
"#fortawesome/vue-fontawesome": "^3.0.0-4",
"core-js": "^3.6.5",
"pinia": "^2.0.14",
"vue": "^3.0.0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.15",
"#vue/cli-plugin-eslint": "~4.5.15",
"#vue/cli-service": "~4.5.15",
"#vue/compiler-sfc": "^3.0.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0",
"sass": "^1.26.5",
"sass-loader": "^8.0.2",
"vue-cli-plugin-pinia": "~0.1.3"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
and here you can find my main.js file:
import { createApp } from "vue";
import App from "./App.vue";
import { library } from "#fortawesome/fontawesome-svg-core";
import { faCartShopping } from "#fortawesome/free-solid-svg-icons";
import { createPinia } from "pinia";
import { FontAwesomeIcon } from "#fortawesome/vue-fontawesome";
library.add(faCartShopping);
const pinia = createPinia();
createApp(App)
.use(pinia)
.component("font-awesome-icon", FontAwesomeIcon)
.mount("#app");
Here is my github if someone want to check the code: https://github.com/Elsong1120/Ecomm-challenge
Thanks to anyone who will help me.
Had similar issues this is what helped me:
1st create a new file in store folder \store\store.js wich looks like this:
import { createPinia, setActivePinia } from "pinia";
const pinia = createPinia();
setActivePinia(pinia);
export default pinia;
2nd import the pinia (exported from \store\store.js) into your main.js
import { createApp } from 'vue';
import pinia from './stores/store.js';
import App from './App.vue';
const app = createApp(App);
app.use(pinia)
app.mount('#app');
Webpack.config.vendor.js
const treeShakableModules = [
'#angular/animations',
'#angular/common',
'#angular/compiler',
'#angular/core',
'#angular/forms',
'#angular/http',
'#angular/platform-browser',
'#angular/platform-browser-dynamic',
'#angular/router',
'zone.js',
];
const nonTreeShakableModules = [
'bootstrap',
'bootstrap/dist/css/bootstrap.css',
'#angular/material',
'#angular/material/prebuilt-themes/indigo-pink.css',
'#angular/cdk',
'es6-promise',
'es6-shim',
'event-source-polyfill',
'jquery',
];
Package.json
{
"name": "VotingWebsite",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "karma start ClientApp/test/karma.conf.js"
},
"devDependencies": {
"#angular/animations": "^5.2.2",
"#angular/cli": "^1.6.6",
"#angular/common": "5.2.2",
"#angular/compiler": "5.2.2",
"#angular/compiler-cli": "5.2.2",
"#angular/core": "5.2.2",
"#angular/forms": "5.2.2",
"#angular/http": "5.2.2",
"#angular/platform-browser": "5.2.2",
"#angular/platform-browser-dynamic": "5.2.2",
"#angular/platform-server": "5.2.2",
"#angular/router": "5.2.2",
"#ngtools/webpack": "1.9.6",
"#types/chai": "4.1.2",
"#types/jasmine": "2.8.5",
"#types/webpack-env": "1.13.3",
"angular2-router-loader": "0.3.5",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.4.1",
"bootstrap": "3.3.7",
"chai": "4.1.2",
"css": "2.2.1",
"css-loader": "0.28.9",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.12",
"expose-loader": "0.7.4",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.6",
"html-loader": "0.5.5",
"isomorphic-fetch": "2.2.1",
"jasmine-core": "2.9.1",
"jquery": "3.3.1",
"json-loader": "0.5.7",
"karma": "2.0.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.1",
"karma-webpack": "2.0.9",
"preboot": "6.0.0-beta.1",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.12",
"rxjs": "5.5.6",
"style-loader": "0.19.1",
"to-string-loader": "1.1.5",
"typescript": "2.6.2",
"url-loader": "0.6.2",
"webpack": "3.10.0",
"webpack-hot-middleware": "2.21.0",
"webpack-merge": "4.1.1",
"zone.js": "0.8.20"
},
"dependencies": {
"#angular/cdk": "^5.2.0",
"#angular/material": "^5.2.0",
"angular-polyfills": "^1.0.1",
"hammerjs": "^2.0.8",
"material-design-icons": "^3.0.1",
"web-animations-js": "^2.3.1"
}
}
Vendor.css
#import '~https://code.getmdl.io/1.3.0/material.indigo-pink.min.css'
Component.html
<div class="example-container">
<mat-form-field>
<input matInput placeholder="Input">
</mat-form-field>
</div>
app.share.module.ts
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { FormsModule } from '#angular/forms';
import { HttpClientModule } from '#angular/common/http';
import { RouterModule } from '#angular/router';
import 'hammerjs';
import 'angular-polyfills';
import 'web-animations-js';
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import { AppComponent } from './components/app/app.component';
import { EqualValidator } from "./components/Validation/equal.validator.directive";
import { HomeComponent } from './components/home/home.component';
import { LoginComponent } from './components/usercreation/login.component';
import { MobileComponent } from './components/mobile/mobile.component';
import { SocialComponent } from './components/usercreation/social.component';
import { RegisterComponent } from './components/usercreation/signup.component';
import { DashBoardComponent } from './components/dashboard/dashboard.component';
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import {
MatAutocompleteModule,
MatButtonModule,
MatButtonToggleModule,
MatCardModule,
MatCheckboxModule,
MatChipsModule,
MatDatepickerModule,
MatDialogModule,
MatExpansionModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatFormFieldModule,
MatListModule,
MatMenuModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatRadioModule,
MatRippleModule,
MatSelectModule,
MatSidenavModule,
MatSliderModule,
MatSlideToggleModule,
MatSnackBarModule,
MatSortModule,
MatStepperModule,
MatTableModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule
} from '#angular/material';
import { BrowserModule } from '#angular/platform-browser';
import { platformBrowserDynamic } from '#angular/platform-browser-dynamic';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
#NgModule({
declarations: [
AppComponent, RegisterComponent, EqualValidator, DashBoardComponent,
HomeComponent, NavMenuComponent,
LoginComponent,
MobileComponent,
SocialComponent
],
imports: [
CommonModule,
HttpClientModule,
FormsModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: 'mobile', component: MobileComponent },
{ path: 'dashboard', component: DashBoardComponent },
{ path: 'signup', component: RegisterComponent },
{ path: '**', redirectTo: 'home' }
]),
BrowserModule,
BrowserAnimationsModule,
MatAutocompleteModule,
MatButtonModule,
MatButtonToggleModule,
MatCardModule,
MatCheckboxModule,
MatChipsModule,
MatStepperModule,
MatDatepickerModule,
MatDialogModule,
MatExpansionModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatFormFieldModule,
MatListModule,
MatMenuModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatRadioModule,
MatRippleModule,
MatSelectModule,
MatSidenavModule,
MatSliderModule,
MatSlideToggleModule,
MatSnackBarModule,
MatSortModule,
MatTableModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule
],
exports: [
MatAutocompleteModule,
MatButtonModule,
MatButtonToggleModule,
MatCardModule,
MatCheckboxModule,
MatChipsModule,
MatStepperModule,
MatDatepickerModule,
MatDialogModule,
MatExpansionModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatFormFieldModule,
MatListModule,
MatMenuModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatRadioModule,
MatRippleModule,
MatSelectModule,
MatSidenavModule,
MatSliderModule,
MatSlideToggleModule,
MatSnackBarModule,
MatSortModule,
MatTableModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule
]
})
export class AppModuleShared {
}
Followed the instruction form https://getmdl.io/started/index.html
https://material.angular.io/
Tried the solution from this link Angular material Could not find Angular Material core theme
Could not find Angular Material core theme
http://www.mithunvp.com/angular-material-2-angular-cli-webpack/
https://www.codeproject.com/Tips/1189201/Adding-Angular-Material-in-ASP-NET-Core-Angular-SP
But still not able to resolve the issue. The input box and other design are not working.
Keep getting the error as Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming
Trying to solve this issue from past 1 day but no luck. Can anyone please let me know where I, am doing wrong.
The problem is that webpack was not referesh. So use the node.js command or cmd to run the below command.
webpack --config webpack.config.vendor.js
Visual studio doesn't refresh the command on running the project on development environment. However it runs on the production environment.
If the webpack is not install use the command below to install globally and you can run the above command.
npm install -g webpack
This solve my issue.
Using latest version of Angular Material in ASP.net Core 2.0 is more difficult and time consuming for resolving package dependencies.
Use below version of angular material in package.json
"#angular/cdk": "^2.0.0-beta.12"
"#angular/material": "^2.0.0-beta.12"
followed by run below command to install it.
npm install --save
It looks like the angular cdk and material are installed correctly. Otherwise you will get an error about that instead.
However, make sure that the material css is also loaded by editing angular.json and adding node_modules/#angular/material/prebuilt-themes/indigo-pink.css to the section projects->[project name]->architect->build->styles below src/styles.css
I've tested this with ASP.Net Core 3 and Angular 8.2.