There is a problem that Customize Ant Design Theme is not applied - css
I am customizing the theme of antd while using next.js.
After Googling the related information, I found a good example and completed the setup as follows.
// package.json
"dependencies": {
"#ant-design/icons": "^4.8.0",
"antd": "^4.24.3",
"next": "^12.3.1",
"next-plugin-antd-less": "^1.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^5.3.6",
"styled-reset": "^4.4.2"
},
"devDependencies": {
"babel-plugin-import": "^1.13.5"
}
// .babelrc
{
"presets": [
"next/babel"
],
"plugins": [
[
"import",
{
"libraryName": "antd",
"style": true
}
]
]
}
// next.config.js
const withAntdLess = require('next-plugin-antd-less');
module.exports = withAntdLess({
modifyVars: { '#primary-color': '#04f' },
lessVarsFilePath: './styles/variables.less',
lessVarsFilePathAppendToEndOfContent: false,
cssLoaderOptions: {},
webpack(config) {
return config;
},
});
// styles/variables.less
#import '~antd/lib/style/themes/default.less';
#import '~antd/dist/antd.less';
#primary-color: #52c41a;
// pages/app.js
import React from 'react';
import { ThemeProvider } from 'styled-components';
import "../styles/variables.less";
import GlobalStyles from '../styles/GlobalStyles';
import Theme from '../styles/Theme';
const Home = ({ Component, pageProps }) => {
return (
<>
<GlobalStyles />
<ThemeProvider theme={Theme}>
<Component {...pageProps} />
</ThemeProvider>
</>
);
};
export default Home;
// log of executing npm run dev command
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn - Invalid next.config.js options detected:
- The root value has an unexpected property, modifyVars, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, future, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).
- The root value has an unexpected property, lessVarsFilePath, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, future, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).
- The root value has an unexpected property, lessVarsFilePathAppendToEndOfContent, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, future, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).
- The root value has an unexpected property, cssLoaderOptions, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, future, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).
See more info here: https://nextjs.org/docs/messages/invalid-next-config
info - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc.js" https://nextjs.org/docs/messages/swc-disabled
info - Using external babel configuration from C:\Users\Administrator\OneDrive\Desktop\Training\.babelrc.js
event - compiled client and server successfully in 23.4s (193 modules)
After completing the setting, when I ran the code, the setting was not applied contrary to my expectations.
I might have made a mistake in my code, so I went back to the reference material and tried the settings again, the result was the same.
Is there something wrong with my settings?
We would appreciate it if you could leave a comment in the reply.
Related
How to develop/debug two apps with shared components using vue3 and vite?
I'm building a couple of apps with vue3 and vite, using some shared components. The production build process works OK but I'm having a problem with dev/debug. The Vite docs (for multi-page apps) says "During dev, simply navigate or link to /nested/ - it works as expected, just like for a normal static file server." but I don't know what this means - how do I link to a sub folder? I have added /src/app1 to url in launch.json, but it has no effect. I have also tried using cd src\app1 in the terminal before running npm run dev "version": "0.2.0", "configurations": [ { "type": "firefox", "request": "launch", "name": "vuejs: firefox -width 300 -height 600 -P default", "url": "http://localhost:5173/src/app1", "webRoot": "${workspaceFolder}", "pathMappings": [ { "url": "file:///C:", "path": "c:" } ] } ] (This launch.json works well with a simple single-page app). What happens with trying to debug one of the apps is that the project launches but with an empty index.html (i.e. a blank screen with no errors). I'm pretty sure the basic project structure is OK because (as I said) the build process works; I get two separate outputs of html+css+js both of which work as expected, with the correct shared components. Also, if I tell the Vite server to automatically open the page (as I have done in my vite.config.js below) the page opens correctly - although without a debugger attached of course. So I guess that the settings in launch.json are incorrect. The project structure is: -src -app1 -app.vue -index.html -main.js -app2 -app.vue -index.html -main.js -assets ... -shared -components -shared.vue If I have just one index.html, moved up a level, I can debug each app but only by editing it every time to point to a different main.js and to change the title, which seems a laborious way of approaching the task. Below is my vite config. The extra lines in alias were added as an attempt to solve the problem but they are probably incorrect (or unneccesary) import { fileURLToPath, URL } from 'node:url' import { resolve } from 'path' import { defineConfig } from 'vite' import vue from '#vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], server: { base: '/src/app1', open: '/src/app1/index.html', }, resolve: { alias: { vue: 'vue/dist/vue.esm-bundler.js', '#': fileURLToPath(new URL('./src', import.meta.url)), app1: fileURLToPath(new URL('./src/app1', import.meta.url)), app2: fileURLToPath(new URL('./src/app2', import.meta.url)), // shared: fileURLToPath(new URL('./src/shared/components', import.meta.url)), } }, build: { rollupOptions: { input: { app1: resolve(__dirname, './src/app1/index.html'), app2: resolve(__dirname, './src/app2/index.html'), }, }, }, })
I've made things more complex than neccesary because I missed the important setting. In vite.config.js, it's important to define root to point to where each index.html is found. So for my structure above, the config file looks like import { defineConfig } from 'vite' import vue from '#vitejs/plugin-vue' export default defineConfig({ plugins: [vue() ], root: "src\app1", resolve: { alias: { vue: 'vue/dist/vue.esm-bundler.js', } } }) In the process I've also swapped from Firefox to Chrome for debug (I was getting a lot of irrelevant error messages from Firefox), and my launch.json is now simply { "version": "0.2.0", "configurations": [ { "type": "chrome", "request": "launch", "name": "Launch Chrome against localhost", "url": "http://localhost:5173", "webRoot": "${workspaceFolder}", } ] } It doesn't really matter what the file structure looks like, as long as within each file its dependencies are correctly addressed. The only important bit is the root. Simply by changing that from 'app1' to 'app2' will switch both the debug and the build to the correct folders, with the release (built) files being stored in subfolders of 'app1' and 'app2' independently. It would be easy to extend this to have more than 2 apps each sharing the same common components.
nuxt3 and vuetify3 Slow page response
I have created a front development environment using docker compose. The configuration is nginx + nuxt3 + vuetify3. I created vue in the Pages directory. It took 120000ms to display it. It's so slow that I can't even develop. I'm trying to see why it's taking so long. and it looks like it is getting all the vuetify code. Also some of the requests are giving errors. http://host.docker.internal/_nuxt/node_modules/vuetify/lib/components/VChip/VChip.css http://host.docker.internal/_nuxt/node_modules/vuetify/lib/components/VGrid/VGrid.css http://host.docker.internal/_nuxt/node_modules/nuxt/dist/pages/runtime/app.vue http://host.docker.internal/_nuxt/node_modules/vuetify/lib/components/VNoSsr/VNoSsr.mjs?v=afbc0ebb http://host.docker.internal/_nuxt/node_modules/vuetify/lib/components/VColorPicker/util/index.mjs?v=afbc0ebb http://host.docker.internal/_nuxt/node_modules/vuetify/lib/components/VList/VListChildren.mjs?v=afbc0ebb http://host.docker.internal/_nuxt/node_modules/vuetify/lib/components/VProgressCircular/VProgressCircular.css?v=afbc0ebb The access is from host.docker.internal:80 leading to host machine:80 -> nginx container:80 -> nuxt container:3000. The nuxt server is run by this command. npx nuxi dev I don't know why the above massive requests are taking place. It also does not appear to be normal. What is wrong? I am new to both nuxt and vuetify. I am also not familiar with how webpack works.
Having the same issue, maybe it would be wise to add your nuxt config. Maybe someone can figure out what to do.. Mine is as followed: { ... css: ['vuetify/styles'], build: { transpile: ['vuetify'], }, modules: [ // eslint-disable-next-line require-await async (_options, nuxt) => { // #ts-ignore nuxt.hooks.hook('vite:extendConfig', (config) => config?.plugins && config.plugins.push(vuetify({ autoImport: true }))) }, ], ... And plugins/vuetify.ts // #ts-ignore import {defineNuxtPlugin, useRuntimeConfig} from '#app' import {createVuetify} from 'vuetify' import * as components from 'vuetify/components' import {aliases, mdi} from 'vuetify/iconsets/mdi-svg' import { md3 } from 'vuetify/blueprints' import {useDark} from '#vueuse/core' export default defineNuxtPlugin((nuxtApp) => { const isDark = useDark().value const vuetify = createVuetify({ ssr: true, // https://next.vuetifyjs.com/en/features/blueprints/ blueprint: md3, components, icons: { defaultSet: 'mdi', aliases, sets: { mdi, }, }, // https://next.vuetifyjs.com/en/features/theme/ theme: { defaultTheme: isDark ? 'dark' : 'light', themes: { dark, // theme defined earlier light, // theme defined earlier }, }, }) nuxtApp.vueApp.use(vuetify) })
Nextjs translation from api no locale in path
I am new in NextJs and trying to migrate an actual React app to a NextJs app I have three locales on my website en, fr, es, the landing page path is different depending on the user locale /home, /accueil, /inicio First, I tried to manage my locales with next-i18next I had a little issue as you can't get translations from api, I had to download them on build but the bigger issue was that I had to have the locale in the url /en/home, /fr/accueil, /es/inicio and I do not want that. So then I tried to move to react-i18next my i18n.js file import i18n from 'i18next' import LanguageDetector from 'i18next-browser-languagedetector' import { initReactI18next } from 'react-i18next' import Backend from 'i18next-http-backend'; i18n .use(initReactI18next) .use(LanguageDetector) .use(Backend) .init({ backend: { loadPath: `...`, }, react: { useSuspense: false }, supportedLngs: ['en', 'fr', 'es'], fallbackLng: ['en'], detection: { order: ['cookie', 'navigator'], lookupCookie: 'i18nextLng', caches: ['cookie'], cookieOptions: { path: '/', sameSite: 'strict' }, checkWhitelist: true } }) export default i18n And then I am including it in my _app.js import Layout from '../components/layout' import '../i18n'; import '../styles/globals.scss' function MyApp({ Component, pageProps }) { return ( <Layout> <Component {...pageProps} /> </Layout> ) } export default MyApp; But I have the following warning Text content did not match. Server: "Brand" Client: "brand.name" Should be because i18n is loading the translation on client side and not on server side The translations should be loaded from getStaticProps but I do not know if I can adapt react-i18next to do so or use a lower level of i18n
If you use the i18n feature of Next.js you need to have the language in the url: https://nextjs.org/docs/advanced-features/i18n-routing To directly use react-i18next, you may have a look at: https://react.i18next.com/latest/ssr btw: there is currently a pending PR for next-i18next that will enable client side translation loading: https://github.com/isaachinman/next-i18next/pull/1726 (https://github.com/i18next/i18next-http-backend/tree/master/example/next)
Include node_modules css in Vuejs application that uses scss
I have deployed my application to aws and I see that the application renders fine, except that the syncfusion controls do not render correctly. Google chrome console does not show any errors. The application renders correctly in my local machine. To fix this, it was suggested I move the import '#syncfusion/**/styles/material.css' statements in the individual vue component to App.vue (as documented here). I however get a "Failed to resolve loader: sass-loader, You may need to install it" error(the application has node-sass, sass-loader installed already). How should I include css files along with scss files, in my application? Before: vocabulary.vue: <script> import '#syncfusion/ej2-base/styles/material.css'; import '#syncfusion/ej2-vue-inputs/styles/material.css'; package.json: "devDependencies": { "node-sass": "^4.12.0", "sass-loader": "^7.1.0", } vue.config.js: module.exports = { publicPath: '/', transpileDependencies: [ 'vue-echarts', 'resize-detector' ], configureWebpack: { devtool: 'source-map', optimization: { splitChunks: { chunks: 'all' } } } } App.Vue: <style> #import "../node_modules/#syncfusion/ej2-base/styles/material.css"; #import "../node_modules/#syncfusion/ej2-vue-inputs/styles/material.css"; </style>
Deleting the npm packages and re-installing them again fixed the issue.
Why does there appear to be non deterministic behavior trying to load a babel plugin in a nextjs project? Next - Babel
I have a nextjs app with redux. When I try to use the ?? operator in my pages/index, it works as it should. I then tried to load up a redux store with a bunch of reducers. When I hit the ?? in a reducer file, I get this error: Support for the experimental syntax 'optionalChaining' isn't currently enabled (71:32): I also get the error in any other file: component, actions and reducers. It is only directly in the pages/* that the plugin is working properly. My app is using next#9.1.1 and redux#4.0.4. Here is my .babelrc file: "env": { "development": { "presets": ["next/babel"], "plugins": [ "#babel/plugin-proposal-optional-chaining", "#babel/plugin-proposal-nullish-coalescing-operator", [ "styled-components", { "ssr": true, "displayName": true, "preprocess": false } ] ] } } } Is there something that would override my babel config for certain files? If so, what am I missing? What else should I look at?