I m using webcomponents but without sass support.
there is this file direflow-webpack.js that i can override the normal webpack and add my rules.
Problems:
Inside the component file, it cant find the scss module.
import styles from '../../sass/main.scss';.The application is using
typescriptand also thebuildandrunprocess gives no errors.This is how i used to add sass, on a
webpack.config, on my previous projects:
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
},
},
{
loader: require.resolve('postcss-loader'),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebookincubator/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
],
},
},
],
},
//add sass loader for .scss files
{
test: /\.scss$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader" // compiles Sass to CSS
},{
loader: "postcss-loader"
}]
},
- This is my current simple
direflow-webpack.js, which i added the new rules for thesass(i m not sure if it is correct):
module.exports = (config, env) => ({
...webpackConfig(config, env, {
filename: 'bundle.js',
},
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
},
},
{
loader: require.resolve('postcss-loader'),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebookincubator/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
],
},
},
],
},
//add sass loader for .scss files
{
test: /\.scss$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader" // compiles Sass to CSS
},{
loader: "postcss-loader"
}]
}),
});
I dont get any error in the console, it builds & run without error.
But inside the component file, it cant find the scss module.
import styles from '../../sass/main.scss';
Should i do any configuration in the tsconfig.json as well ?