Z
Z
zirdid2018-05-07 16:43:55
symfony
zirdid, 2018-05-07 16:43:55

How to properly include js/css in Symfony4?

Help me figure out how to connect js/css in Symfony4 with Webpack Encore. I'm trying to connect adminlte for the admin panel. I download it via npm in node_modules and ... how do I proceed to use scripts and styles in templates?
With scripts, if I understand correctly, it's easy - we create a file in assets / js, connect it in it and in the template we already use the file generated via webpack. But what about styles?
var adminlte=require('admin-lte');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2018-05-07
@zirdid

Similarly, bootstrap connection example:
assets/dashboard/js/dashboard.js

var $ = require('jquery');
require('bootstrap');

assets/dashboard/scss/dashboard.scss webpack.config.js
var Encore = require('@symfony/webpack-encore');

Encore
    .setOutputPath('public/assets/')
    .setPublicPath('/assets')
    .cleanupOutputBeforeBuild()
    .enableSourceMaps(!Encore.isProduction())
    .addEntry('js/dashboard', './assets/dashboard/js/dashboard.js')
    .addStyleEntry('css/dashboard', './assets/dashboard/scss/dashboard.scss')
    .enableSassLoader(function(sassOptions) {}, {
        resolveUrlLoader: false
    })
    .autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question