builder-vite icon indicating copy to clipboard operation
builder-vite copied to clipboard

Configuration within a monorepo

Open Jeezy8 opened this issue 4 years ago • 4 comments

Hey folks,

im having issues configuring storybook inside a monorepo. I have storybook in the root and then two packages inside packages/myApp and packages/base these two packages have their own tsconfig.json with baseUrl: './src' The issue is with the absolute imports within these packages. For their compilation everything works fine, vite picks up the absolute imports based on the baseUrl properly.

but for storybook out of the root it does not work. i tried to make it work using a rollup plugin as followed, but without any success:

.storybook/main.js

  async viteFinal(config, { configType }) {
    config.plugins = [
      ...config.plugins,
      pluginNodeResolve.nodeResolve({
        moduleDirectories: ['node_modules', 'packages/myApp/src'],
      }),
    ];
    return config;
  },

Jeezy8 avatar Aug 16 '21 09:08 Jeezy8

also am having this problem, have not found a solution yet

verhichi avatar Sep 09 '21 15:09 verhichi

Would something like this help you?

viteFinal: async (config) => {
    return {
      ...config,
      resolve: {
        alias: [
          {
            find: '~/web',
            replacement: path.resolve(__dirname, '../../web/src'),
          },
          {
            find: '~/server',
            replacement: path.resolve(__dirname, '../../server/src'),
          },
        ],
      },
    }
  },

My setup is a bit different (I have a storybook as a standalone package, not in the root). Also each package has it's own paths resolution.

dannytce avatar Sep 21 '21 19:09 dannytce

Feels to me that this is not respecting managerHead/managerBody from the storybook config. From their docs, it is possible add a .storybook/manager-head.html with <base href="/storybook/" /> (as an example) that would be inserted into the final index.html and adjust the base path for subfolders setups.

I am new here, so couldn't pin point where that should happened though in the code.

filipesperandio avatar Oct 31 '21 16:10 filipesperandio

It would be somewhat analogous to https://github.com/eirslett/storybook-builder-vite/commit/255b7f93257ac2becb05e694618619082027211b

filipesperandio avatar Oct 31 '21 16:10 filipesperandio