-
Hi, I'm trying to use fylgja inside a new Symfony project, on my local machine running a Debian-based Linux distribution. Here is my 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 subdirectory 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())
// configure Babel
// .configureBabel((config) => {
// config.plugins.push('@babel/a-babel-plugin');
// })
// enables and configure @babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = '3.23';
})
// enables Sass/SCSS support
.enableSassLoader()
.enablePostCssLoader()
// 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(); Here is my {
"devDependencies": {
"@babel/core": "^7.17.0",
"@babel/preset-env": "^7.16.0",
"@hotwired/stimulus": "^3.0.0",
"@symfony/stimulus-bridge": "^3.2.0",
"@symfony/webpack-encore": "^4.0.0",
"core-js": "^3.23.0",
"postcss-loader": "^7.0.0",
"regenerator-runtime": "^0.13.9",
"sass": "^1.60.0",
"sass-loader": "^13.0.0",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"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": {
"@fylgja/mq": "^1.2.2",
"@fylgja/utilpack": "^1.2.1",
"fylgja": "^1.3.0"
}
} And here is my @use "@fylgja/theme" with ($color-theme: rebeccapurple,
$color-on-theme: white);
@use "@fylgja/base";
@use "@fylgja/details";
@use "@fylgja/table";
@use "@fylgja/list";
@use "@fylgja/breadcrumbs";
@use "@fylgja/pagination";
@use "@fylgja/avatar";
@use "@fylgja/button";
@use "@fylgja/container";
@use "@fylgja/section";
@use "@fylgja/card";
@use "@fylgja/hashlink";
@use "@fylgja/utilpack"; When I launch the
The issue is coming from the last @use "@fylgja/utilpack"; The compilation works perfectly fine when removing this last line. Any idea ? Thanks a lot ! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hi @bricebou I need to check why this is happening for this specific case. Most likely the it an issue with sass-loader or encore or both, not sure yet. I will first do a test, when I have time, of a clean install with just webpack and sass-loader The issue on top is error from sass-loader that it can not find See the Sass docs for
This weird since your own imports are using the relative path |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot ! I'll stay available if you need me to send more logs or test more :) |
Beta Was this translation helpful? Give feedback.
-
Hi @bricebou, I believe I may have found a solution to your issue. It appears that you need to set the include path to ensure that all node relative paths are handled correctly when using sass-loader. The problem seems to be related to how sass-loader handles imports from node_modules. In both cases that I tested (with Webpack and Encore), passing To fix your issue, please add the following code to your configuration: const Encore = require('@symfony/webpack-encore');
// Other Encore options
Encore
// Other Encore options
.enableSassLoader((options) => {
options.sassOptions = {
includePaths: ["node_modules"],
};
}, {})
;
module.exports = Encore.getWebpackConfig(); Thank you for bringing this issue to my attention. I have also created a repository specifically for JS bundler cases like this, which you can find at fylgja/examples. I will add more options there later 😉. |
Beta Was this translation helpful? Give feedback.
-
Great, thanks a lot @GrimLink ! I'll try that as soon as I can :-) |
Beta Was this translation helpful? Give feedback.
-
@bricebou I have converted this issue to a Q&A discussion. If my answer helpt, please mark the answer as answered, for other people with the same question 😉 |
Beta Was this translation helpful? Give feedback.
Hi @bricebou, I believe I may have found a solution to your issue. It appears that you need to set the include path to ensure that all node relative paths are handled correctly when using sass-loader.
The problem seems to be related to how sass-loader handles imports from node_modules. In both cases that I tested (with Webpack and Encore), passing
includePaths: ["node_modules"]
was necessary, just like when using sass directly.To fix your issue, please add the following code to your configuration: