Problème d'installation bootstrap in webpack sous symfony 5

Par Mimason', il y a 5 ans


Bonjour,

J'ai installé un webpack dans mon projet symfony 5 mais quand je tape la commande $npm run build, j'obtients l'erreur ci-dessous:

Failed to compile. Module parse failed: Unexpected character '@' (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders > @import "custom"; | @import "~bootstrap/scss/bootstrap";

Mon webpack.config.js

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 sub-directory 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()) .configureBabel((config) => { config.plugins.push('@babel/plugin-proposal-class-properties'); }) // enables @babel/preset-env polyfills .configureBabelPresetEnv((config) => { config.useBuiltIns = 'usage'; config.corejs = 3; }) // enables Sass/SCSS support .enableSassLoader() // 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();

Mon package.json

{ "devDependencies": { "@symfony/stimulus-bridge": "^2.0.0", "@symfony/webpack-encore": "^1.0.0", "core-js": "^3.0.0", "css-loader": "^5.2.4", "jquery": "^3.6.0", "node-sass": "^5.0.0", "popper.js": "^1.16.1", "regenerator-runtime": "^0.13.2", "sass-loader": "^9.0.1", "stimulus": "^2.0.0", "webpack": "^5.36.2", "webpack-notifier": "^1.6.0" }, "license": "UNLICENSED", "private": true, "scripts": { "dev-server": "encore dev-server", "dev": "encore dev", "watch": "encore dev --watch", "build": "encore production --progress" }, "dependencies": { "@popperjs/core": "^2.9.2", "autoprefixer": "^10.2.5", "bootstrap": "^5.0.0-beta3", "postcss-loader": "^5.2.0" } }

Mon app.js

/* * Welcome to your app's main JavaScript file! * * We recommend including the built version of this JavaScript file * (and its CSS file) in your base layout (base.html.twig). */ // any CSS you import will output into a single css file (app.css in this case) import './styles/custom.scss'; import './styles/app.scss'; // const $ = require('jquery'); import { Tooltip, Toast, Popover } from 'bootstrap'; // import 'bootstrap/dist/js/bootstrap.min.js'; // import 'bootstrap/dist/css/bootstrap.min.css'; // start the Stimulus application import './bootstrap';

Mon app.css

@import "custom"; @import "~bootstrap/scss/bootstrap";

Mon custom.css

$body-bg: #000; $body-color: #111;

J'ai besoin de votre aide mes amis si vous pouvez le faire !!!

2 réponses

Grafikart, il y a 5 ans

Ton fichier devrait s'appeler app.scss non ?

Mimason', il y a 5 ans

C'est possible mais j'arrive pas à faire ça.