score:0
There is no better solution than replacing the old @import
by the new @use
, and everything should be imported once only
score:2
Had the same issue, managed to resolve it by creating a file bootstrap.imports.scss
that imports my custom variables and the mixins, variables etc. from bootstrap:
@import 'bootstrap_variables'; // contains the custom bootstrap variables
@import '~bootstrap/scss/functions';
@import '~bootstrap/scss/variables';
@import '~bootstrap/scss/mixins';
Then in the webpack config I use the sass-resources-loader
loader like this:
rules: [{
test: /\.(scss)$/,
loaders: ExtractTextPlugin.extract({
fallback: 'style-loader', // in case the ExtractTextPlugin is disabled, inject CSS to <HEAD>
use: [{
loader: 'css-loader', // translates CSS into CommonJS modules
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader', // Run post css actions
options: {
sourceMap: true,
plugins: function () { // post css plugins, can be exported to postcss.config.js
return [
require('postcss-flexbugs-fixes'),
require('autoprefixer')
];
}
}
},
{
loader: 'sass-loader', // compiles SASS to CSS
options: {
sourceMap: true
}
},
{
loader: 'sass-resources-loader',
options: {
resources: [
`${path}/bootstrap.imports.scss`
]
},
}]
})
}]
With this, I am able to import a scss file anywhere and use the botostrap functions or variables
Source: stackoverflow.com
Related Query
- Accessing global variables in Sass with Webpack without multiple imports
- Migrating to Styled-Components with global SASS variables in React
- webpack minify with global variables and methods for selective files in React
- multiple or single imports in es6 with webpack
- How to use import global sass variables with create-react-app (ejected)
- Global scss variables with reactjs and webpack
- Sass with CSS Modules & Webpack
- Next.JS: Using SASS variables from global scss
- Using React Router with CDN and without webpack or browserify
- How to use Webpack Module Federation plugin with create-react-app without ejecting
- Environment variables in Typescript with Webpack
- Webpack imports the same styles multiple times
- Can't import Antd single component without messing up with the global style
- global is not defined while using socket.io-client with webpack
- React.js with Django without using webpack
- Loading SASS Modules with TypeScript in Webpack 2
- Can't access sass variables compile error with react app
- Using external styles and multiple class names with webpack css loader
- Use global parent selector with Sass and CSS Module
- Import SASS variables into Material UI theme with NextJS
- Best way to have absolute imports with Webpack 2?
- React-boilerplate+grommet, making sass work with webpack
- webpack keeps bundling react with each of the multiple entry points
- Compiling Sass with Webpack (and local scope class names)
- Global SASS variables in reactjs app
- How to use global variables in Storybook with React
- validate multiple variables without writing multiple if else statements
- Accessing multiple arrays of data with different numbers
- Searching for Webpack config for React Components Library with Typescript, SASS & CSS Modules via SASS support
- Using TypeScript transpiled code utilizing es6-style classes with imports in a browser without an additional transpilation step?
More Query from same tag
- How to invoke a hook from React class component?
- React Router v6 - Create Invalid Path Redirect
- React js Warning: Don't set the props property of the component. Mutate the existing props object instead
- React.js - How to set a default value for input date type
- socket.io useEffect cleanup function react
- How to place search boxes side by side in React Js
- How to write unit test for render component
- React chart : prevent chart's canvas scaling with height and width
- How to access async function from Redux Action passed into Redux Thunk?
- How to run nested map in Reactjs?
- Disable input field when click edit button using React Hooks
- Error: Module not found: Error: Can't resolve './src/api' in 'D:\opensource\sound-redux\node_modules\soundcloud'
- Cannot read property 'preventDefault' of undefined in react
- Return render of elements without wrapping
- why cleanup function dos not work in react app
- Execute function in React when user stops typing
- react: why static propTypes
- Phonenumber masking in React
- dynamic Progress bar in React
- CORS issue in codeigniter 4: Response to preflight request doesn't pass access control check
- How to make AppBar component from material-ui-next react to scroll events
- Turning props into state after initialisation with GetDerivedStateFromProps?
- Need Help : How do I resolve this function?
- Is this a good way to pass props to child component in React?
- How to fix the Error: Objects are not valid as a React child (found: object with keys {})
- How to update data of parent component after database update?
- React testing mock implementation one, work with mocked funcitons
- How to use FormattedMessage inside an option tag in React 0.14?
- How to use callback function in React hooks when value is submitted?
- Webpack Not Creating CSS Files, issues with style-loader, css-loader, sass-loader