Multi theme nextjs - next.js

I am building a multi theme application as it will be deployed on different urls using different themes.
My idea was to use an env variable, in my case APPLICATION_VERSION which can be v1, v2 or v3
I am passing the variable to my sass using next.config.js
const { i18n } = require('./next-i18next.config');
/** #type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
i18n,
sassOptions: {
prependData: `$theme: ${process.env.APPLICATION_VERSION};`,
},
env: {
APPLICATION_ENVIRONMENT: process.env.APPLICATION_ENVIRONMENT,
APPLICATION_LOCALES_KEY: process.env.APPLICATION_LOCALES_KEY,
APPLICATION_VERSION: process.env.APPLICATION_VERSION,
}
}
module.exports = nextConfig
Then in my scss I created a mixin
#mixin isTheme($value) {
#if $theme == $value {
#content;
}
}
In local this is working with some issues, when I am changing the APPLICATION_VERSION value I have to edit all my *.module.scss files so the isTheme mixin is taken into account.
I tried to deploy it with vercel and seems that the isTheme mixin is ignored
This is my build script where vars are passed
#!/bin/bash
rm package-lock.json
npm i
node ./bin/locales.js
npm i -g vercel
DEPLOYMENT_URL=$(VERCEL_ORG_ID=$VERCEL_ORG_ID VERCEL_PROJECT_ID=$VERCEL_PROJECT_ID vercel --confirm \
--token $VERCEL_TOKEN \
--build-env APPLICATION_ENVIRONMENT=staging \
--env APPLICATION_ENVIRONMENT=staging \
--build-env APPLICATION_VERSION=$APPLICATION_VERSION \
--env APPLICATION_VERSION=$APPLICATION_VERSION \
--regions fra1 )
vercel alias set $DEPLOYMENT_URL $APPLICATION_URL -t $VERCEL_TOKEN --scope $SCOPE
But when deployed threw vercel the content of isTheme mixin is not displayed

Related

Symfony won't find routes after git-pull on a new computer, Encore not compiling right either

I have Git-pulled a symfony 5 project that works fine on the computer it was created, to pick it up on an new workstation. But when I launch my app, I get errors about the requested routes not existing. I also get an error when running "yarn encore dev".
Does anyone know what I missed ?
After git pulling, I've run :
symfony server:ca:install
composer install
yarn add --dev #symfony/webpack-encore
yarn add webpack-notifier --dev
yarn encore dev
The last command fails with that :
yarn encore dev
yarn run v1.22.19
$ C:\Users\Elyss\Documents\GitHub\NewFormadil\deux\Formadil\node_modules\.bin\encore dev
Running webpack ...
ERROR Failed to compile with 3 errors 15:10:13
Module build failed: Module not found:
"./assets/app.js" contains a reference to the file "bootstrap-star-rating".
This file can not be found, please check it for typos or update it if the file got moved.
"./assets/app.js" contains a reference to the file "bootstrap-star-rating/css/star-rating.css".
This file can not be found, please check it for typos or update it if the file got moved.
"./assets/app.js" contains a reference to the file "bootstrap-star-rating/themes/krajee-svg/theme.css".
This file can not be found, please check it for typos or update it if the file got moved.
Entrypoint app [big] 1.92 MiB = runtime.js 14.6 KiB vendors-node_modules_symfony_stimulus-bridge_dist_index_js-node_modules_bootstrap_dist_js_boo-43ff9a.js 1.88 MiB app.css 395 bytes app.js 21.8 KiB
webpack compiled with 3 errors
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
If I try and symfony:serve anyway, I get the following symfony error, although the route does exist and works fine on the original install :
RouteNotFoundException
RuntimeError
HTTP 500 Internal Server Error
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "login" as such route does not exist.").
I've tried a "yarn upgrade", clearing caches and bunch of other ways to get everything up to date, but with no success.
Here is the webpack.config.js:
const Encore = require('#symfony/webpack-encore');
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry('app', './assets/app.js')
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
.enableStimulusBridge('./assets/controllers.json')
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
.splitEntryChunks()
// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
.configureBabel((config) => {
config.plugins.push('#babel/plugin-proposal-class-properties');
})
// enables #babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
// enables Sass/SCSS support
//.enableSassLoader()
// uncomment if you use TypeScript
//.enableTypeScriptLoader()
// uncomment if you use React
//.enableReactPreset()
// uncomment to get integrity="..." attributes on your script & link tags
// requires WebpackEncoreBundle 1.4 or higher
//.enableIntegrityHashes(Encore.isProduction())
// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;
module.exports = Encore.getWebpackConfig();
And the package.json:
{
"devDependencies": {
"#hotwired/stimulus": "^3.0.0",
"#popperjs/core": "^2.11.4",
"#symfony/stimulus-bridge": "^3.0.0",
"#symfony/webpack-encore": "^1.8.1",
"bootstrap": "^5.1.3",
"core-js": "^3.0.0",
"jquery": "^3.6.0",
"regenerator-runtime": "^0.13.2",
"webpack-notifier": "^1.15.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production --progress"
},
"dependencies": {
"#fortawesome/fontawesome-free": "^5.15.4",
"autoprefixer": "^10.4.2",
"chart.js": "^3.7.0",
"composer": "^4.1.0",
"postcss-loader": "^6.2.1",
"sass": "^1.48.0",
"sass-loader": "^12.4.0",
"scoop": "^0.0.2"
}
}

When i run npm run watch, i get TypeError: The 'compilation' argument must be an instance of Compilation, does anyone know why?

I am currently working on a website using symfony and i use webpack to compile the CSS and JS. When i try npm run watch, i get the following :
TypeError: The 'compilation' argument must be an instance of Compilation
at Function.getCompilationHooks (C:\Users\Louis\desktop\NEWPLANTE-2\node_modules\webpack\lib\NormalModule.js:227:10)
at C:\Users\Louis\desktop\NEWPLANTE-2\node_modules\#symfony\webpack-encore\lib\webpack-manifest-plugin\index.js:56:24
at _next46 (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:50:1)
at _next24 (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:97:1)
at _next2 (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:144:1)
at Hook.eval [as call] (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:152:1)
at Hook.CALL_DELEGATE [as _call] (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\Hook.js:14:14)
at Compiler.newCompilation (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\webpack\lib\Compiler.js:1122:26)
at C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\webpack\lib\Compiler.js:1166:29
at Hook.eval [as callAsync] (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
I already checked, webpack is installed only once so there is no duplicate.
I tried several times deleting package.json, package-lock.json and node_modules and re running npm install But i still got the same error when running npm run watch.
Node and npm are already up to date so it should not be an update problem.
PS C:\Users\Louis\desktop\NEWPLANTE-2> npm -v
8.13.2
PS C:\Users\Louis\desktop\NEWPLANTE-2> node -v
v16.14.2
Here is the content of my package.json file
{
"devDependencies": {
"#hotwired/stimulus": "^3.0.0",
"#symfony/stimulus-bridge": "^3.0.0",
"#symfony/webpack-encore": "^1.8.1",
"core-js": "^3.0.0",
"regenerator-runtime": "^0.13.2",
"webpack-notifier": "^1.6.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production --progress"
}
}
Im not the only member in this project, i have checked with my teammates, the npm run watch is working for them. I am not sure why mine is not working although we have the same code and the same files.
Here is the content of webpack.config.js
const Encore = require("#symfony/webpack-encore");
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || "dev");
}
Encore
// directory where compiled assets will be stored
.setOutputPath("public/build/")
// public path used by the web server to access the output path
.setPublicPath("/build")
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry("app", "./assets/app.js")
.addEntry("homepage", "./assets/homepage.js")
.addEntry("about", "./assets/about.js")
.addEntry("annonce", "./assets/annonce.js")
.addEntry("contact", "./assets/contact.js")
.addEntry("faq", "./assets/faq.js")
.addEntry("mentions", "./assets/mentions.js")
.addEntry("signup", "./assets/signup.js")
.addEntry("profil", "./assets/profil.js")
.addEntry("createAnnonce", "./assets/createAnnonce.js")
.addEntry("signup2", "./assets/signup2.js")
.addEntry("validation", "./assets/validation.js")
.addEntry("cgu", "./assets/cgu.js")
.addEntry("error404", "./assets/error404.js")
.addEntry("login", "./assets/login.js")
.addEntry("payment", "./assets/payment.js")
.addEntry("recap", "./assets/recap.js")
.addEntry("verify", "./assets/verify.js")
.addEntry("errors", "./assets/errors.js")
// .splitEntryChunks()
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
.enableStimulusBridge("./assets/controllers.json")
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
.splitEntryChunks()
// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
.configureBabel((config) => {
config.plugins.push("#babel/plugin-proposal-class-properties");
})
// enables #babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = "usage";
config.corejs = 3;
});
// enables Sass/SCSS support
//.enableSassLoader()
// uncomment if you use TypeScript
//.enableTypeScriptLoader()
// uncomment if you use React
//.enableReactPreset()
// uncomment to get integrity="..." attributes on your script & link tags
// requires WebpackEncoreBundle 1.4 or higher
//.enableIntegrityHashes(Encore.isProduction())
// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
module.exports = Encore.getWebpackConfig();

Error with date/time fields in EasyAdmin once deployed on Heroku

I work on a Symfony 6.0.9 website with EasyAdmin to handle the administration panel.
I've got an entity ProfessionalExperience with some of its properties that are dates. Its CRUD controller for EasyAdmin looks like this :
class ProfessionalExperienceCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return ProfessionalExperience::class;
}
public function configureCrud(Crud $crud): Crud
{
...
}
public function configureFields(string $pageName): iterable
{
return [
...
DateTimeField::new('start')
->setFormat('Y-MM-dd'),
DateTimeField::new('stop')
->setFormat('Y-MM-dd'),
...
];
}
}
It works just fine in my dev env and the build and deploy on Heroku works fine too.
But when I try to click to access this part of the administration panel in the deployed website, I've got this error in Heroku's logs :
[critical] Uncaught PHP Exception LogicException: "When using date/time fields in EasyAdmin backends, you must install and enable the PHP Intl extension, which is used to format date/time values." at /app/vendor/easycorp/easyadmin-bundle/src/Field/Configurator/DateTimeConfigurator.php line 37
I don't understand, because in my Dockerfile, I've got this :
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
libzip-dev \
zlib-dev \
; \
\
docker-php-ext-configure zip; \
docker-php-ext-install -j$(nproc) \
intl \
zip \
; \
Thanks for helping me ! ;)
You could try adding the extension in your composer.json.
You can see in the heroku documentation that you can add optionnal extension to install by adding them in your composer.json.
{
"require": {
"ext-intl": "*",
}
}
Don't forget to run composer update and commit your lock file.

nextjs+Dockerfile: env variables pass to nextjs.config.js

I have a next.config.js
module.exports = {
.........
env: {
BASE_URL: 'http://xx.xx.xx.xx:8000',
},
............
};
Now I want to change the BASE_URL while building docker image
my Dockerfile file
FROM node:16-alpine3.14
WORKDIR /usr/app
COPY ./package.json ./
RUN yarn install
ENV BASE_URL=http://yy.yyy.yy.yy:80
# Copy all files
COPY ./ ./
RUN yarn build
So passing ENV BASE_URL=http://yy.yyy.yy.yy:80 in Dockerfile will it help to change the BASE_URL: 'http://xx.xx.xx.xx:8000' in the next.config.js
Or what the way i can change the BASE_URL
ENV BASE_URL=http://yy.yyy.yy.yy:80 in your docker file will set an environment variable BASE_URL to it's value, you need to read it for that variable.
//next.config.js
module.exports = {
.........
env: {
BASE_URL: process.env.BASE_URL || 'http://xx.xx.xx.xx:8000', //read the value from env id empty use default value.
},
............
};

PostCSS not purging

I am on Windows 10 with Node v14.15.4 and npm 6.14.10
I have executed below command successfully
npm install -D tailwindcss#latest postcss#latest autoprefixer#latest postcss-cli cssnano onchange
This has no effect :
"tw:prod": "SET NODE_ENV=production postcss build ./src/css/tailwind.css -o ./public/css/tailwind.css",
If I remove SET NODE_ENV=production it works but public/css/tailwind.css is still 3.2MB.
"tw:prod": "postcss build ./src/css/tailwind.css -o ./public/css/tailwind.css",
Why isn't it purging ?
You probably have to create a configuration file and provide the paths of your templates in the purge option.
npx tailwindcss init
// tailwind.config.js
module.exports = {
purge: [
'./src/**/*.html',
'./src/**/*.vue',
'./src/**/*.jsx',
],
theme: {},
variants: {},
plugins: [],
}

Resources