I am a newbie in composer and Heroku cloud and here has a may-be-stupid question about the path in composer.
I am trying to deploy a Wordpress on Heroku, following the code/instruction here: https://github.com/ellefsen/wordpress-heroku-php
In concept, I should use S3 to store any media content. However, my case is quite special: there are two and only two images for my site, now and in future. So I:
removed all S3 related code and configs;
add two images in public/content/uploads/ as: public/content/uploads/2016/08/one.png and public/content/uploads/2016/08/another.png;
adjust the .gitignore accordingly (remove the public/content/uploads);
Modify the composer.json as:
"extra": {
"webroot-dir": "public/wp",
"webroot-package": "wordpress",
"installer-paths": {
"public/content/plugins/{$name}/": [
"type:wordpress-plugin"
],
"public/content/mu-plugins/{$name}/": [
"type:wordpress-muplugin"
],
"public/content/uploads/{$name}/": [
"public/wp/wp-content/uploads/{$name}"
],
"public/content/themes/{$name}/": [
"type:wordpress-theme"
]
}
},
For item "public/content/uploads/{$name}/", I tried:
public/wp/wp-content/uploads/{$name}
wp-content/uploads/{$name}
But in any case, within the WP dashboard, I cannot see any image in the media lib. Could someone please give me a hand? Thanks!
I would not bother with the Media Library in WP as long as you are only dealing with two images. Just put them in your theme directory and reference them directly.
That way you won't have to deal with S3 or Heroku's ephemeral file storage as they would all be committed and included with your repository as part of your project.
Related
I'm currently trying to learn how to implement SASS into my web development projects but I'm struggling a little bit with figuring out how to properly compile my .scss files into one single .css file.
When I run sass --version in my terminal, I receive 1.53.0 compiled with dart2js 2.17.3. As far as extensions go, I'm using Live Sass Compiler by Glenn Marks, and within the settings.json file, my configuration looks like this:
{
"liveSassCompile.settings.formats":[
{
"format": "expanded",
"extensionName": ".css",
"savePath": "/css"
},
],
"liveSassCompile.settings.excludeList": [
"**/node_modules/**",
".vscode/**"
],
"liveSassCompile.settings.generateMap": true,
"liveSassCompile.settings.autoprefix": [
"defaults"
]
}
This is my current project directory:
Current Project Directory Structure
My current issue is that whenever I click Watch Sass, the only file I want to be output is the main.css and main.css.map but it creates an index.css and index.css.map file as well.
I'm trying to implement something similar to the 7 - 1 SASS Architecture, and within each of those folders I created an index.scss that'll contain each file in it's directory, which will then be #forward to the main.scss.
Is there any particular way I can avoid the extra files being created? I'm not too familiar with npm but I've heard it would be more beneficial to learn it in order to utilize SASS as opposed to using a VS Code extension and I'm more than open to taking that approach and scrapping the entire extension as a whole if it proves to be more efficient.
Thank you for your help in advanced, I hope I provided enough information!
Dart sass comes with an inbuilt compiler
Just run the code
sass --watch sass/main.scss css/main.css
This one faulty line is probably the reason for your problem.
Change this:
"liveSassCompile.settings.generateMap": true,
to this:
"liveSassCompile.settings.generateMap": false,
If you decide to stick with my extension then you can specify a single file to output/watch with the liveSassCompile.settings.includeItems setting - as shown below
{
"liveSassCompile.settings.includeItems": [ "/path/to/main.scss" ]
}
Alternatively, and possibly a better solution, you can use a negative glob expression in the liveSassCompile.settings.partialsList to treat every other file as a partial. Then, when any SASS file is saved, it triggers compilation of just your main.scss file
When I'm trying to build the Next.Js app then the below error is coming with a successful build. This error is showing when I deploy the app in Vercel.
error - ESLint: Failed to load config "next/babel" to extend from. Referenced from: /vercel/path0/.eslintrc.json
This is my .eslintrc.json
{
"extends": ["next/babel","next/core-web-vitals"]
}
I've also added .babelrc
{
"presets": ["next/babel"],
"plugins": []
}
I also found a solution when I change the eslintrc.json file like below:
{
"extends": ["next","next/core-web-vitals"]
}
then no error is showing while building the app. But there is another problem showing when I use the above solution and the problem is:
Parsing error: Cannot find module 'next/babel'
This is shown in all the imports with red marks.
I tried to search the solution but did not found any solution for this.
I think, this might have to do with this weird hackfix that is being touted in a bunch of places that tells you to place next/babel in your eslint config file for some reason (e.g. here).
It probably was a hackfix for an old bug in older next.js versions. But as of (at least) summer 2022, it makes little sense to do so, considering that next/babel is a babel preset, not an eslint preset. Instead, in recent next.js versions, just reset your .eslintrc.json:
{
"extends": [
"next"
]
}
With this setup, things don't error out, as of next#12.2.*.
You also might want to take a look next's eslint customization options. For example, some people might be confused why eslint is seemingly not working.
In that case, consider this solution and the next.js docs on eslint.
If you have this problem, but you did not copy+paste your .eslintrc.json from the interwebz, then you might need to describe your situation in more detail.
my problem has been solved by this code. just copy and paste it into the eslintrc.json file.
{
"extends": ["next/babel","next/core-web-vitals"]
}
Or just replace "next" and "next/core-web-vitals" to
"plugin:#next/next/recommended"
https://nextjs.org/docs/basic-features/eslint
I had this issue when working with TurboRepo. The solution for me was to add next as a devDependency in the root of the monorepo.
Same Turborepo issue using pnpm. This solved it for me: https://github.com/vercel/next.js/issues/40687#issuecomment-1275184829
Essentially add this to your settings.json
// .vscode/settings.json
{
"eslint.workingDirectories": [
{ "pattern": "apps/*/" },
{ "pattern": "packages/*/" }
]
}
I have this folder structure:
sass/main.sass
css/main.css
js/...
img/...
I want the sass output to go to the css folder, but each time I run sass watcher it creates a new css file within the sass directory among sass files.
Thx for information about using 'Live SASS Compiler' in VS Code.
To set special otuput pathes to your project you need to add the settings for output pathes to the settigns.json of your project:
File: `projectDIR/.vscode/settings.json'
Example for setting the save pathes to output directory:
"settings": {
// output: generate files to ...
// ~ = path starts relative from scss-file
"liveSassCompile.settings.formats":[
{
"format": "expanded",
"extensionName": ".css",
"savePath": "~/../assets"
},
// ad a compressed version
{
"format": "compressed",
"extensionName": ".min.css",
"savePath": "~/../assets"
}
// optional: add more outputs ...
],
}
See also official example in web: https://github.com/ritwickdey/vscode-live-sass-compiler/blob/master/docs/settings.md
Additional hint:
VERSION OFF 'LIVE SASS COMPILER' MAY BE OUTDATED
The actual commmon used Extension Live Sass Compiler is not longer supported (for years now). It uses an outdated SASS Version. The most recent features like #use are not supported in that version. You use that outdated version if author is 'Ritwick Dey'.
But there is an active supported fork with same name 'Live SASS Compiler' build by 'Glenn Marks'. As fork it works the same way and the settings are almost the same. Or you can use another actual compiler which is faster as you can use an direct installed SASS Version on your system. In that case you need to change the settings for your project.
Information about that you will find here:
https://stackoverflow.com/a/66207572/9268485
Updated: Correction name of author of supported extension 'Live SASS Compiler' to correct identification of extension.
Go to path: C:\Users\your user\AppData\Roaming\Code\User\settings.json
and change there the "liveSassCompile.settings.formats" section
for example:
the parameter : "savePath": "/Python/CSS",
I have several questions on my ASP.NET MVC CORE 2.2 project.
The main goal is very simple, i want to update my stylesheet and then deploy this result. I have a Site.less, site.css, site.min.css, site.min.css.gz that i want to update with a css class style, a bundleconfig.json with my input css, javascript files to be bundled and a compilerconfig.json that has Site.less as an input and site.css as output. I also have BuildBundlerMinifier installed on my project (NuGet).
Questions:
1- What file should i update when adding some new style: Site.less, site.css or both?
2- What are the steps to minify and bundle before i publish my app?
bundleconfig.json:
[
{
"outputFileName": "wwwroot/css/bundle.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
(...)
"wwwroot/css/Site.min.css"
]
},
(...)
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
]
compilerconfig.json
[
{
"inputFile": "wwwroot/css/Site.less",
"outputFile": "wwwroot/css/site.css"
}
]
When i rebuild my project in my Output window (Visual Studio 2017) i have the following messages.
Cleaning output from bundleconfig.json,
Done cleaning output file from bundleconfig.json, Begin processing bundleconfig.json, Minified wwwroot/css/bundle.min.css, Done processing bundleconfig.json
Thank you.
My first question is answered.
I have installed an extension in Visual Studio 2017 (Tools -> Extensions and Updates) named Web Compiler. When i make an update in my less file, the css file and min.css are auto generated (min.css.gz is not and don't know why). The files that the code is auto generated are water marked with Generated keyword.
To produce the auto generated files you only need to rebuild the project.
This works with other files but in my case i am only using this ones.
EDIT
My second question is also answered.
I have installed another extension: Bundler & Minifier
To produce bundle you need to have those config json files i have posted in my first post and then open Task Runner Explorer and double click on wwwroot/css/bundle.min.css (inside StyleSheets menu) and the bundle file will be auto generated.
My source file starts like this:
<?php
/**
* #package JpLists
*/
namespace Inc\Pages;
use WP_List_Table;
class ListTable extends WP_List_Table {
I end up with the following error in the browser when trying to extend a standard WordPress class:
Fatal error: Class 'WP_List_Table' not found in /srv/www/wordpress/wp-content/plugins/jpLists/inc/Pages/ListTable.php on line 9
This post suggests Composer + WordPress plugins is a bad idea
I'm just about to throw in the towel and go back to hard-coded require_once() calls, but the idea of namespaces & autoloading appeals to me.
my composer.json file looks like:
{
"name": "jp/jp-lists",
"description": "WordPress plugin",
"type": "wordpress-plugin",
"license": "GPL",
"authors": [
{
"name": "JP",
"email": "jp#example.com"
}
],
"minimum-stability": "dev",
"require": {},
"autoload": {
"psr-4":{"Inc\\": "./inc"}
}
}
It turns out if you just add a '\' before the name, PHP knows that you are referring to a class in global namespace and not the namespace specified at the beginning fo the file.
use \WP_List_Table;
I had abandoned my effort to use namespaces and composer for a couple of months, but after some diligent studying on namespaces, I decided to tackle the problem again and it was a simple fix.
Composer's autoloader will take care of autoloading classes in your namespace (Inc). You have a problem with loading WP_List_Table, but this is not your class - it is WordPress core class and autolader from your project will not even try to load it (since it does not have any definition where to search it).
Also this class is marked as internal and WordPress documentation discourage from using it in plugins or themes. This is probably the reason why it is not available by default. If you really need it, you should require it manually:
if (!class_exists('WP_List_Table')) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
Or just copy it to your project under different name and use it, just like documentation recommends:
This class's access is marked as private. That means it is not intended for use by plugin and theme developers as it is subject to change without warning in any future WordPress release. If you would still like to make use of the class, you should make a copy to use and distribute with your own project, or else use it at your own risk.
https://codex.wordpress.org/Class_Reference/WP_List_Table
Please add the following to composer.json.
[example case: wp-content/plugins/example/src/composer.json]
"autoload": {
"files": ["../../../../wp-admin/includes/class-wp-list-table.php"]
}
and Generating autoload files
composer dumpautoload
write into class file
use WP_List_Table;
class Test_WP_List_table extentds WP_List_Table {
.....
but i don't know use ABSPATH method
I am using Google Translate because I can not understand English very well.