I tried to follow instructions from documentation but it doesn't work.
Documentation: https://symfony.com/doc/current/frontend/encore/simple-example.html
The code I have:
assets/js/app.js
require('./assets/css/app.scss');
const $ = require('jquery');
in webpackconfig
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('js', './assets/js/app.js')
.enableSassLoader()
.autoProvidejQuery()
const $ = require('jquery');
base.html.twig
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('build/app.scss') }}">
<link rel="stylesheet" href="{{ asset('~/bootstrap/css/bootstrap.css') }}">
{% endblock %}
And the error message in my console
127.0.0.1/:7 GET http://127.0.0.1:8000/~/bootstrap/css/bootstrap.css
net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:6 GET http://127.0.0.1:8000/build/app.scss net::ERR_ABORTED 404
(Not Found)
app.js:11 Uncaught Error: Cannot find module ".assetscssapp.scss"
at webpackMissingModule (app.js:11)
at Object../assets/js/app.js (app.js:11)
at __webpack_require__ (bootstrap 63d062e87dc6edab6451:19)
at bootstrap 63d062e87dc6edab6451:62
at bootstrap 63d062e87dc6edab6451:62
Thank you !
The files are only created if you have run encore:
Yarn:
yarn run encore production
yarn run encore dev
yarn run encore dev --watch
Then the files can be found unter "/public/build" and asset can find them.
If you make changes to the source files, you'll have to rerun encore. On dev you can use the "-- watch" command
Related
I’m on a new symfony 5 project, with Webpack/encore and sass loader enable.
I also use symfony/apache-pack, so I’m use the following link to access on my web site :
https://localhost/myproject/public/show
I also installed bootstrap, with npm, and I import this css in the sass file : \myproject\assets\styles\app.scss with :
#import '~bootstrap/scss/bootstrap';
When I run a yarn encore dev there are no warning, the css file is in the following directory (with bootstrap inside) :
\myproject\public\build\
My problem is these :
when I use the normal link (I’m on windows with XAMPP) : https://localhost/myproject/public/show , in my twig template, the following twig command doesn’t work :
{{ encore_entry_script_tags('app') }}
links are broken :
I’m required to use for downloading the .css and .js files :
<link rel="stylesheet" href="{{ asset('./build/app.css') }}">
It is very strange, because, when I’m using the internal PHP symfony server (symfony server:start)
I use this URL : https://127.0.0.1/show , and the css could be load.
I don't edit the webpack.config.js (except enabling the sass loader)
Someone can help me, please ?
you must set setPublicPath in 'wbpack.config.js' file to setPublicPath('/show/build')
I'm working on a Symfony 4 project with Webpack Encore for asset management.
I configured my local server with this : https://stackoverflow.com/a/15864222/5158153
I can access to localhost from my Android device but it doesn't get access to any asset.
I tried with another project (not Symfony) and it can get assets.
I think there's something I forgot with webpack config but I don't know what.
Webpack-config.js
const Encore = require('#symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('http://localhost/tharmo/public/build')
.setManifestKeyPrefix('build/')
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
.autoProvidejQuery()
.createSharedEntry('vendor', [
'./assets/js/custom.js',
'materialize-css',
])
.addEntry('app', './assets/js/app.js')
.enableSassLoader()
;
module.exports = Encore.getWebpackConfig();
base.html.twig
<link type="text/css" rel="stylesheet" href="{{ asset('build/app.css') }}"
media="screen,projection" />
It works correctly in Windows where Wamp server is installed but not in Android.
On Android device, if I type the url, I can get the asset so something is wrong with the way I get asset in Twig.
Good installed foundation 5 just downloading and copying files
Now to move on veriaveis the need fondation have a .scss file however does not have anything on my Symfony2 project to use them
config.yml
filters:
cssrewrite: ~
compass: ~
sass: ~
base.html.twig
{% stylesheets "bundles/delivveweb/scss/*" filter="compass" %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
he is generating the css file however when you open the file contains the following error:
[exception] 500 | Internal Server Error | Assetic\Exception\FilterException
[message] An error occurred while running:
'/usr/bin/ruby' '/usr/bin/compass' 'compile' '/tmp' '--boring' '--config' '/tmp/assetic_compassl2wvYW' '--sass-dir' '' '--css-dir' '' '/tmp/assetic_compassH8m6D9.scss'
Error Output:
/usr/bin/ruby: No such file or directory -- /usr/bin/compass (LoadError)
I hope someone can help me install it, if it were possible using composer
Type in console:$whereis compass or which compass
Example output: - compass: /usr/local/bin/compass
Now in config.yml:
filters:
compass:
bin: /usr/local/bin/compass
I Installed Ruby in C:\Ruby200-x64, PATH was set to C:\Ruby200-x64\bin and ran:
gem update --system
gem install sass
gem install compass
Then I configured Assetic in app/config/config.yml:
ruby: C:\Ruby200-x64\bin\ruby.exe
sass: C:\Ruby200-x64\bin\sass.bat
filters:
compass:
bin: C:\Ruby200-x64\bin\compass.bat
In app/Resources/views/base.html.twig I've added the stylesheets block:
{% stylesheets
'css/main.scss' filter="compass" %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
The scss file points to /web/css/main.scss for testing in prod I would use the bundles/bundlename/... paths.
Then, when I tried to install and dump Assets:
php app/console assets:install
php app/console assetic:dump
I got this error while ending paths with .bat:
[Assetic\Exception\FilterException]
An error occurred while running:
"C:\Ruby200-x64\bin\ruby.EXE" "C:\Ruby200-x64\bin\compass.bat" "compile" "C:\Users\Jes·s\AppData\Local\Temp" "--config" "C:\Users\Jes·s\AppData\Local\Temp\assC7D6.tmp" "--sass-dir" "" "--css-dir" "" "C:/Users/Jes·s/AppData/Local/Temp/assC7D7.tmp.scss"
Error Output:
C:/Ruby200-x64/bin/compass.bat:1: syntax error, unexpected tCONSTANT, expecting end-of-input
And this when not using .bat extensions:
[Assetic\Exception\FilterException]
An error occurred while running:
"C:\Ruby200-x64\bin\ruby.exe" "C:\Ruby200-x64\bin\compass" "compile" "C:\Users\Jes·s\AppData\Local\Temp" "--config" "C:\Users\Jes·s\AppData\Local\Temp\ass52DB.tmp" "--sass-dir" "" "--css-dir" "" "C:/Users/Jes·s/AppData/Local/Temp/ass52DC.tmp.scss"
Error Output:
Configuration file, C:\Users\Jes·s\AppData\Local\Temp\ass52DB.tmp, not found or not readable.
I saw these (and others):
How to use SCSS filter in Symfony2 under Windows?
https://github.com/kriswallsmith/assetic/issues/299
https://github.com/symfony/AsseticBundle/issues/158 tried lot of things and I'm stuck...
The version without .bat is correct, however looks like "Jes·s" folder name causes the issue (there should be u with an accent?).
Your config.yml should look something like this
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ AJWPageBundle ]
# compass.bin: W:\Ruby\1.9.2\bin\compass.bat
java: /usr/bin/java
ruby: 'W:\Ruby\bin\ruby.exe'
sass: 'W:\Ruby\bin\sass.bat'
filters:
cssrewrite: ~
sass:
bin: %sass.bin%
apply_to: "\.scss$"
compass:
bin: %compass.bin%
closure:
jar: "%kernel.root_dir%/Resources/java/compiler.jar"
yui_css:
jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
parameters:
assetic.ruby.bin: 'W:\Ruby\bin\ruby'
compass.bin: 'W:\Ruby\bin\compass'
sass.bin: 'W:\Ruby\bin\sass'
Make sure you modify the paths to match with your file system.
Note that some have a .exe or .bat at the end some do not
Next in console execute "php app/console assets:install"
This should create directories within web/bundles that match up with your src/bundles directories.
From in there you should find the path to the scss file you will be calling in my example below it would be: bundles/mybundle/css/bootstrap.scss
In your view:
{% stylesheets
'bundles/mybundle/css/bootstrap.scss' output='css/*.css' filter="compass" %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
And then finally in console execute "php app/console assetic:dump"
This should be all that you have to do at this particular point in time 2/1/2014 - I did not need to modify any of the batch files for ruby
You will find that assetic will find the file web/bundles/mybundle/css/bootstrap.css and any other css file you may add, combine them and then save them to web/css/nameoffile_123456.css with some number appended to the end to make sure that if there is an update the browser is forced to download the new version.
I am trying to configure symfony assetic manager to compile my less css files and rewrite paths however I am getting the following error:
Dumping all dev assets.
Debug mode is on.
18:51:01 [file+] C:/htdocs/site-ideiah-symfony/app/../web/css/57b3454.css
[Assetic\Exception\FilterException]
An error occurred while running:
"C:\Users\Rafael\AppData\Local\Temp\ass1C74.tmp"
Error Output:
Access Denied
My config.yml
filters:
cssrewrite:
apply_to: '\.(css|less)$'
less:
node: [ "C:\\Program Files\\nodejs\\node.exe" ]
node_paths: [ "C:\\Program Files\\nodejs\\", "C:\\Program Files\\nodejs\\node_modules\\" ]
apply_to: "\.less$"
My template usage
{% block stylesheets %}
{% stylesheets filter='less,cssrewrite'
'#IdeiahSiteAppBundle/Resources/public/less/style.less'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="all" />
{% endstylesheets %}
{% endblock %}
I am using Windows 8 with PHP 5.4.7, Does anyone knows how could i fix it?
The Error Output: Access Denied message implies that it is a security related issue.
This security issue can be related to either 1) not being able to write the output files, 2) not being able to read the input files, and/or 3) not being able to execute the node command
1) Is the user that is running the assetic:dump command able to write to the folder C:/htdocs/site-ideiah-symfony/web/css/ and the 57b3454.css file ?
2) After the Error Output:, assetic should also display the input used, similar to this:
Input:
/*!
* Bootstrap v2.3.1
*
* Copyright 2012 Twitter, Inc
* Licensed under the Apache License v2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Designed and built with all the love in the world #twitter by #mdo and #fat
*/
// Core variables and mixins
#import "variables.less"; // Modify this for custom colors, font-sizes, etc
#import "mixins.less";
// CSS Reset
#import "reset.less";
Do you see any input listed ?
3) Check if the user execute "C:\Program Files\nodejs\node.exe" from the command-line
I had a similar issue. Removing Less and installing an older version fixed it for me. One of the other solutions seems to be upgrading symfony to a newer version, but we were unable to do this because of having to use an older version of symfony which is compatible with centos6.5
This helped: https://github.com/braincrafted/bootstrap-bundle/issues/217