在Stroybook中使用自定义Webpack配置文件时,未定义“ exports”

时间:2018-10-11 07:35:26

标签: javascript webpack storybook

我在我的Storybook配置目录.storybook中使用了自定义Webpack配置文件,运行命令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 / addon-knobs”:“ ^ 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

0 个答案:

没有答案