I'm working on a skeleton to have (for myself or whoever wants it) with webpack react express and ssr (server side rendering).
I'm having an issue where i cant import scss in react components.
For some reason I can import them in the files where I do ReactDOM.hydrate
I've tried hundreds of different webpack configurations, and also tried generating a single css file, which I wasn't able to also.
scss config
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader']
}
package.json dependencies:
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"autoprefixer": "^9.4.3",
"babel-loader": "^8.0.4",
"clean-webpack-plugin": "^1.0.0",
"css-loader": "^2.1.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"html-webpack-plugin": "^3.2.0",
"isomorphic-style-loader": "^4.0.0",
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.11.0",
"nodemon": "^1.18.9",
"postcss-loader": "^3.0.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"url-loader": "^1.1.2",
"webpack": "^4.28.2",
"webpack-cli": "^3.1.2",
"webpack-node-externals": "^1.7.2"
"axios": "^0.18.0",
"express": "^4.16.4",
"react": "^16.7.0",
"react-dom": "^16.7.0"
Simple hydrate file where I can require scss:
require('./index.scss');
const React = require('react');
const ReactDOM = require('react-dom');
const Search = require('./Search');
ReactDOM.hydrate(<Search text={window.__INITIAL__.text} />,
document.getElementById('root'));
same component passed to hydrate where i cannot add the require cause it makes webpack compilation break.
const React = require('react')
const Nav = require('../../components/nav/Nav.js')
class Search extends React.Component {
constructor(props) {
super(props);
this.state = {
text: props.text || null,
}
}
render() {
return (
<div id="main">
<Nav />
<p>{this.state.text}</p>
</div>
);
}
}
module.exports = Search;
I'm trying to get the require or import to work inside each component, but so far wasn't able to.