alias not working
See original GitHub issuemain.js
const path = require("path")
const reactRefresh = require("@vitejs/plugin-react-refresh")
module.exports = {
stories: [
// "../src/**/*.stories.@(js|jsx|ts|tsx)"
"../src/components/**/*.stories.@(ts|tsx)",
],
// addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
core: {
builder: "storybook-builder-vite",
},
resolve: {
alias: [
{
find: "@",
replacement: path.resolve(__dirname, "./src"),
},
{
find: "@assets",
replacement: path.resolve(__dirname, "./src/assets"),
},
{
find: "@components",
replacement: path.resolve(__dirname, "../src/components"),
},
],
},
async viteFinal(config, { configType }) {
// customize the Vite config here
config.resolve.alias.foo = "bar"
reactRefresh()
return config
},
}
If use yarn run
not storybook, config like https://github.com/vitejs/vite/issues/279
work run.
But i believe vite.config.ts != main.js. This plugin can’t handle some features
like vite.config.ts
Requirement:
[1] show case how to use reactRefresh
plugin like we did in vite.config.ts. Cuz reactRefresh is a must for react to work in ite. In vite. Also mention, there is another plugin @vite/vue
should be imported if develop vue.
[2] support vite-tsconfig-paths
in storybook. So, we can have alias support (there may be quite way to solve, this is the major feature needs to be, for storybook to work with alias)
vite.config.ts
import { defineConfig } from "vite"
// import tsconfigPaths from "vite-tsconfig-paths"
import reactRefresh from "@vitejs/plugin-react-refresh"
// import envCompatible from "vite-plugin-env-compatible"
import path from "path"
export default defineConfig({
plugins: [reactRefresh()],
build: {
outDir: "build",
},
// alias: {
// "@": path.resolve(__dirname, "./src"),
// },
// resolve: {
alias: [
{
find: "@",
replacement: path.resolve(__dirname, "./src"),
},
{
find: "@assets",
replacement: path.resolve(__dirname, "./src/assets"),
},
{
find: "@components",
replacement: path.resolve(__dirname, "./src/components"),
},
],
// },
// plugins: [tsconfigPaths(), envCompatible(/* options */), reactRefresh()],
})
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"paths": {
"@components/*": ["./components/*"],
"@assets/*": ["./assets/*"],
},
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "es5",
"types": ["node", "vite/client"]
},
"include": ["./src"]
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
why alias names defined in .bashrc file are not working?
Usually your aliases in .bashrc are defined before the /etc/bashrc call. Try to define them after. Here an example of your .bashrc ...
Read more >Why is my alias now not working? - command line - Ask Ubuntu
You have a space between the = and the opening ' . Remove it. $ alias foo= 'bar baz' bash: alias: bar baz:...
Read more >My Bash aliases don't work - Stack Overflow
bash_aliases is sourced from the default .bashrc on Ubuntu boxes; I don't have access to one to confirm. However, it is not a...
Read more >kali linux - Why bash aliases commands are not working?
When you source ~/.bash_aliases nothing happens because you are sourcing a file that doesn't have your alias up.
Read more >A Quick Guide on How to Use Bash Alias - Shell Tips!
This post cover the Bash builtin commands alias and unalias. You will often find Bash alias in a customized .bashrc to improve your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In the function
viteFinal(config, { configType })
, the parameterconfig
is the config object for vite, which is used bystorybook-builder-vite
. You can return a new config object.// main.js
If you want to reuse the project’s vite.config.js, you can use the API
mergeConfig
andloadConfigFromFile
exposed by vite.☝️ this is the right answer