简体   繁体   English

Nx Storybook Webpack“开发”模式

[英]Nx Storybook Webpack 'DEVELOPMENT' mode

I'm trying to get my Storybook to stop outputting minified JS and subsequent untraceable errors... It seems like it might be due to the way Nx configures Webpack out of the box?我试图让我的 Storybook 停止输出缩小的 JS 和随后的无法追踪的错误......这似乎是由于 Nx 开箱即用配置 Webpack 的方式所致? I can't seem to figure out how to alter this though我似乎无法弄清楚如何改变这个

// .storybook/webpack.config.js
/**
 * Export a function. Accept the base config as the only param.
 * @param {Object} options
 * @param {Required<import('webpack').Configuration>} options.config
 * @param {'DEVELOPMENT' | 'PRODUCTION'} options.mode - change the build configuration. 'PRODUCTION' is used when building the static version of storybook.
 */
module.exports = async ({ config, mode }) => {
  // Make whatever fine-grained changes you need

  // Return the altered config
  return config;
};
// .../.storybook/webpack.config.js
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const rootWebpackConfig = require('../../../.storybook/webpack.config');
/**
 * Export a function. Accept the base config as the only param.
 *
 * @param {Parameters<typeof rootWebpackConfig>[0]} options
 */
module.exports = async ({ config, mode }) => {
  config = await rootWebpackConfig({ config, mode });

  const tsPaths = new TsconfigPathsPlugin({
    configFile: './tsconfig.base.json',
  });

  config.resolve.plugins
    ? config.resolve.plugins.push(tsPaths)
    : (config.resolve.plugins = [tsPaths]);
...

Run cmd: nx run exampleApp:storybook运行 cmd: nx run exampleApp:storybook

Any ideas on how to fix?关于如何解决的任何想法?

Workaround from pitops on github github 上 Pitops 的解决方法

// webpack.config.js
config.plugins.forEach((plugin) => {
    if (plugin.constructor.name === 'DefinePlugin') {
      plugin.definitions['process.env'] = {
        NODE_ENV: JSON.stringify('development'),
        NODE_PATH: JSON.stringify(''),
        PUBLIC_URL: JSON.stringify('.'),
      }
    }
  })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM