1

我在我的 Storybook 配置目录中使用自定义 webpack 配置文件.storybook,运行命令后start-stroybook,我的exports is not defined页面上出现错误。

这是自定义 webpack 配置文件的内容:

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
  plugins: [
    new webpack.optimize.ModuleConcatenationPlugin(),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.DefinePlugin({
      __IS_NATIVE__: JSON.stringify(false),
      'process.env.NODE_ENV': JSON.stringify('development'),
    }),
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
        },
        exclude: path.join(__dirname, '../node_modules'),
      },
      {
        test: /\.svg$/,
        issuer: /\.js$/,
        use: [
          {
            loader: 'babel-loader',
          },
          () => {
            this.counter = this.counter || 0;
            return {
              loader: 'react-svg-loader',
              options: {
                jsx: true,
                svgo: {
                  plugins: [
                    {
                      cleanupIDs: {
                        prefix: `${this.counter++}`,
                      },
                    },
                  ],
                },
              },
            };
          },
        ],
      },
      {
        test: /\.svg$/,
        issuer: /\.css$/,
        use: 'svg-url-loader',
      },
      {
        test: /\.((png)|(eot)|(woff)|(ttf)|(gif)|(jpg)|(otf))$/,
        use: 'url-loader?name=/[hash].[ext]',
      },
      {
        test: /\.ico$/,
        use: 'file-loader',
      },
      {
        test: /\.json$/,
        use: 'json-loader',
      },
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: [
          'style-loader',
          'css-loader?modules&importLoaders=1' +
            '&sourceMap?&localIdentName=[path]-[local]-[hash:base64:5]',
          'postcss-loader',
        ],
      },
    ],
  },
  resolve: {
    modules: ['node_modules', 'pretend_modules'],
  },
};

我正在运行的 Storybook 版本以及可选的任何受影响的插件:

  • @storybook/addon-actions": "^3.4.11
  • @storybook/addon-centered": "^3.4.11
  • @storybook/addon-info": "^3.4.11
  • @storybook/插件旋钮": "^3.4.11
  • @storybook/react": "^3.4.11
  • @babel/core": "^7.0.0-beta.42
  • babel-loader": "^8.0.0-beta.2
  • @babel/preset-env": "^7.0.0-beta.42
4

0 回答 0