// composer.json
{
"require": {
"php": "^7.2.0",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^1.6", // 1.8.1
"doctrine/doctrine-cache-bundle": "^1.2", // 1.3.2
"doctrine/doctrine-fixtures-bundle": "~3.0", // 3.0.2
"doctrine/doctrine-migrations-bundle": "^1.2", // v1.3.1
"doctrine/orm": "^2.5", // v2.7.2
"friendsofsymfony/jsrouting-bundle": "^2.2", // 2.2.0
"friendsofsymfony/user-bundle": "dev-master", // dev-master
"sensio/framework-extra-bundle": "^5.1", // v5.1.5
"symfony/asset": "^4.0", // v4.0.4
"symfony/console": "^4.0", // v4.0.4
"symfony/flex": "^1.0", // v1.17.6
"symfony/form": "^4.0", // v4.0.4
"symfony/framework-bundle": "^4.0", // v4.0.4
"symfony/lts": "^4@dev", // dev-master
"symfony/monolog-bundle": "^3.1", // v3.1.2
"symfony/polyfill-apcu": "^1.0", // v1.7.0
"symfony/serializer-pack": "^1.0", // v1.0.1
"symfony/swiftmailer-bundle": "^3.1", // v3.1.6
"symfony/twig-bundle": "^4.0", // v4.0.4
"symfony/validator": "^4.0", // v4.0.4
"symfony/yaml": "^4.0", // v4.0.4
"twig/twig": "2.10.*" // v2.10.0
},
"require-dev": {
"symfony/debug-pack": "^1.0", // v1.0.4
"symfony/dotenv": "^4.0", // v4.0.4
"symfony/phpunit-bridge": "^4.0", // v4.0.4
"symfony/web-server-bundle": "^4.0" // v4.0.4
}
}
// package.json
{
"devDependencies": {
"@symfony/webpack-encore": "^0.19.0", // 0.19.0
"bootstrap": "3", // 3.3.7
"copy-webpack-plugin": "^4.4.1", // 4.4.1
"font-awesome": "4", // 4.7.0
"jquery": "^3.3.1", // 3.3.1
"node-sass": "^4.7.2", // 4.7.2
"sass-loader": "^6.0.6", // 6.0.6
"sweetalert2": "^7.11.0", // 7.11.0
"webpack-notifier": "^1.5.1" // 1.5.1
}
}
14 Comments
there Copy is now available: https://symfony.com/blog/en...
If you ever get a warning from Yarn like this:
An unexpected error occurred: "EPERM: operation not permitted, unlink '.....\\node_modules\\.bin\\encore'"
Before you try to install jquery, please stop encore. I spent quite a while figuring out why yarn couldn't delete node_modules/.bin/encore... on my Windows 10 machine. *Doh!*
Hey JAVroegop
Nice tip, thanks for sharing it :)
Cheers!
I need some help.
I want to add an external js lib in the right way. This js lib needs to be in the same scope as my code in my entry.
All I have is the link the link:
<script src="https://sdk.example.api.js"></script>What I tried:
import '../api.js'does not work the script throws an errormessage that it's not allowed to run the script like this and that I should load it like this:<script src="https://sdk.example.api.js"></script>I have no idea how the script knows how its loaded but is there anything I can do?
Hey Daniel W.
Your approach of downloading the JS file and then importing it is the right way but I believe the library you're trying to use was written a way that's not compatible with Webpack. As an example, there are some old jQuery plugins that cannot be used with Webpack
Cheers!
Hi! everyone, after installing the sweetalert2 plugin, i'm having this error in the browser. After followed along all the steps.
- Installation (yarn add sweetalert2 --dev)
- Removing the script tag from index.html.twig
- Removing the swal global variable from the function argments at the top and the bottom
- Adding the require line (const swal = require('sweetalert2');)
In chrome, i'm having this error:
Uncaught TypeError: Cannot read property 'constructor' of undefined
at SweetAlert (sweetalert2.all.js:2524)
at RepLogApp.handleRepLogDelete (RepLogApp.js:83)
at HTMLDivElement.dispatch (jquery-3.1.1.min.js:3)
at HTMLDivElement.q.handle (jquery-3.1.1.min.js:3)
In Firefox developer edition, i'm having this one:
TypeError: this is undefined[En savoir plus] rep_log.js line 21 > eval:2524:7
SweetAlert webpack:///./node_modules/sweetalert2/dist/sweetalert2.all.js?:2524
handleRepLogDelete webpack:///./public/assets/js/RepLogApp.js?:83
handleRepLogDelete self-hosted:974
jQuery 2
I've already checked on google, but I've just found something about a ".fire" function which is now available inside the "swal" object. Some said that it worked for them, but i'm so new to javascript, i don't even know where to put it in ryan's code. I've even try to install the same version on "jquery" and "sweetalert2" as him, but it doesn't change anything. I'm a symfony back-end developper (trying to become full-stack) and I'm just trying to start working with webpack since i know it's a great tool.
Don't know what to do. May i have a help please.
Thanks guys
Well, i eventually found out it was just a version matter. The version above 8 seems (Cause mine installed version "sweetalert2@8.2.4") to not be working properly. So i installed the exact same version as Ryan ("sweetalert2@7.12.0"), and it does.
You can also execute "yarn add sweetalert2@^7.11.0 --dev".
Thanks
Hey crgbe,
Thank you for getting back on this problem, it might be helpful for others.
Cheers!
Why is sweetalert2 installed with --dev? In Symfony, using composer the --dev makes sense for debug-pack, webserver, fixtures, etc. But SweetAlert (and jQuery, etc.) are using the final app, not just during development. Obviously, it works, but I'm uncertain about when something should be installed using --dev.
Hey Michael,
Good question! Actually, all your Node dependencies are dev because nothing of them is publicly available, right? Because node_modules/ as also assets/ folders are behind the server document root, i.e. outside of public/ folder. What to expose is up to you, and you do this with Webpack Encore that moves all the *prod* assets into the public/build/ folder that is available for everyone. So, technically ALL your Node packages that you install with npm/yarn are for *dev* only. But really, it is not important at all, you can move them all to the "dependencies" section and nothing will change. Really, you need to care about "devDependencies" and "dependencies" if you write a Node JS server application.
I hope it clarify things for you.
Cheers!
I'am trying to install a yarn plugin called: <a target="_blank" href="https://yarnpkg.com/en/package/autoprefixer"> autoprefixer </a>.
Autoprefixer auto fills css for different browsers.
In my webpack.config.js i've added:
In my backend.js i've added
But when i run yarn run encore dev --watch i get errors. Hope someone could help me out.
Hey Bertin!
... not to ignore your question... but I might have a better solution for doing this. Encore already supports PostCss (just call enablePostCss) - I see you added this manually in your code, but this isn't necessary. PostCss (as I think you know) can be used to integrate with autoprefixer. In fact, if I remember correctly, when you call enablePostCss(), Encore will give you an error that you need to create a config file, and the config contents it suggests include the code needed to enable autoprefixer (you likely already have this config file). So basically, you add one line to webpack.config.js, add one config file, install a few packages (which Encore will tell you) and... that should be it!
Let me know if this helps!
Hey weaverryan
It works.
I just enabled enablePostCss() in webpack.config.js
When running yarn run encore dev --watch, i get the message package 'postcss-loader' missing.
After adding the package and run the comment again, it says: FIX create a postcss.config.js file.
I've created this file at the root
Now it works
And when i look in my compiled css
position: sticky; has now also position: -webkit-sticky; (created by autoPrefixer).
But i've some questions:
I've seen some options on git, <a href="https://github.com/symfony/webpack-encore/pull/130">webpack-encore pull 130</a>
But don't now how to use it within webpack.encore.js.
See my webpack.config.js below with an example but not working
Some other question, in the video about Copy image you mentioned that encore would have an copy feature in the future. Is this already being implemented?
Hey Bertin!
Woohoo! I'm so happy it's working! This is exactly the "workflow" I was hoping people would have to enable this feature :).
> 1. Now i need to add the postcss.config.js file to the root but is there a way to change the path, eq to /assets/configs/
Hmm. The commented-out config you have looks perfect. When you try this, do you get an error? Or does it just not see the file in the new location? If you completely move the file to the new location (and use that config), is there an error or does it just not work correctly? I'm not sure what's going wrong here.
> 2. Some other question, in the video about Copy image you mentioned that encore would have an copy feature in the future. Is this already being implemented?
Booo. No, not yet. Here's the PR: https://github.com/symfony/.... It's blocked due to some problems in an upstream library. I'm not sure if we'll be able to work around that, or if we'll just need to implement something ourself.
Cheers!
"Houston: no signs of life"
Start the conversation!