I am configuring webpack for react storybook and I am having issues with the import statements paths. When I normally run my app, I have a path like this:
import { constructURLName } from "src/shared/utilities/stringManipulation";
I am using the reactQL boilerplate and it is configured so that it will return the proper module based on the src folder. How can I replicate that in storybook? Storybook currently tries to look for that stringManipulation file here:
/Users/me/development/reactQL/node_modules/src/shared/utilities/stringManipulation
So it needs to go up one directory based on my layout:
node_modules
src
pages
...
shared
utilities
stringManipulation
This is what my rule looks like for js/jsx files:
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
query: {
babelrc: false,
presets: [
["env", { modules: false, exclude: ["transform-regenerator"] }],
"react"
],
plugins: [
"transform-object-rest-spread",
"syntax-dynamic-import",
"transform-regenerator",
"transform-class-properties",
"transform-decorators-legacy"
]
}
}
]
},
How can I properly set the src directory? Thanks!
publicPath specifies the virtual directory in web server from where bundled file, app. js is going to get served up from. Keep in mind, the word server when using publicPath can be either webpack-dev-server or express server or other server that you can use with webpack.
The easiest way to get your webpack. config. js file to work is to place it at the top level of your project's folder structure along with your package.
The entry object is where webpack looks to start building the bundle. The context is an absolute string to the directory that contains the entry files.
You can use resolve.modules
.
const path = require('path');
const config = {
...
resolve: {
modules: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, './'),
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With