I have a Create React App written in Typescript, I will call it MyApp. I want to run this App inside an already existing React App, I will call it ExistingApp.
I would like to use it as follows:
import App from "node_modules/@MyApp/src"
function ExistingApp() {
return (
<div className="App">
<App />
</div>
);
}
export default ExistingApp;
I would like to do this compilation/Transpiling using Webpack. I would like the folder structure to be maintained without bundling everything into a single JS file. I have managed to achieve the desire outcome with
tsc --module commonjs --outDir dist
However my .scss files are not being copied to the dist folder. the dist folder only contains the transpilled js files.
The below solution is to get webpack to use Sass, with bundling. If you do not want bundling, I wouldn't use webpack at all.
npm i --save-dev sass-loader node-sass mini-css-extract-plugin css-loader style-loader
{
test: /\.(s(a|c)ss)$/,
use: [MiniCssExtractPlugin.loader,'css-loader', 'sass-loader']
}
import * as MiniCssExtractPlugin from "mini-css-extract-plugin"
OR
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
{
test: /\.(s(a|c)ss)$/,
use: ['style-loader','css-loader', 'sass-loader']
}