I am creating a small reactjs app which in the end will generate a single .js file (it's basically a chatbot frontend application, which talks to a backend). I have created a react app using npx create-react-app, and I have designed everything without problems.
Also I have created a webpack powered proof of concept to generate the js file, and that was working too. Long story short, it was all about specifying the output in the webpack.config.js file:
output: {
path: path.resolve(__dirname, "public"),
library: "StewieWidget",
libraryTarget: "umd",
umdNamedDefine: true,
filename: "[name].js"
}
Now, the generated app uses react-scripts under the hoods, and not webpack explicitly, to the best of my understanding. So, I don't know how to make it "emerge" and pass the above configuration. Also, while digging on Google, I have found that I could potentially use craco, and that's what I did. After reading its configuration, I have seen that, potentially, the webpack documentation can be injected like this:
const path = require('path');
module.exports = {
style: {
postcss: {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
},
},
webpack: {
configure: (webpackConfig, { env, paths }) => {
webpackConfig.entry = {
"mylib": './src/index.js'
}
webpackConfig.output = {
path: path.resolve(__dirname, "public"),
library: "mylib",
libraryTarget: "umd",
umdNamedDefine: true,
filename: "[name].js"
}
console.log(webpackConfig);
return webpackConfig;
}
},
devServer: {
port: 3000,
open: false
}
}
which is clearly not working, and if I launch the app with npm run start --verbose I see that it hangs like this:
which is not very helpful. The start command simply executes craco start.
So, my questions are:
- is craco che best way to handle this ?
- should I go straight on webpack usage ? If so, what's a good tutorial for something like I need to do (as a backend dev, webpack is always been a tough topic)
Thanks for help !
