const path = require('path')
// 在这里你可以重写storybook 默认的webpack配置
module.exports = async ({ config, mode }) => {
  // `mode` has a value of 'DEVELOPMENT' or 'PRODUCTION'

  // 新加sass语法加载器
  config.module.rules.push({
    test: /\.s[ac]ss$/,
    use: ['style-loader', 'css-loader', 'sass-loader'],
    include:path.join('<%= ROOT_PATH %>','./')
  })

  // 新加less语法加载器
  config.module.rules.push({
    test: /\.less$/,
    use: ['style-loader', 'css-loader', 'less-loader'],
    include:path.join('<%= ROOT_PATH %>','./')
  })

  // 改成cdn引入vue
  config.externals = {
    vue: 'Vue'
  }

  // 防止以下依赖从项目组的package.json里查找
  config.resolve = {
    alias: {
      'storybook-addon-mock': path.resolve(__dirname, '../node_modules/storybook-addon-mock'),
      'react': path.resolve(__dirname, '../node_modules/react'),
      'react-dom': path.resolve(__dirname, '../node_modules/react-dom'),
      '@mdx-js/react': path.resolve(__dirname, '../node_modules/@mdx-js/react'),
      '@storybook/addon-docs': path.resolve(__dirname, '../node_modules/@storybook/addon-docs'),
    }
  }

  // Return the altered config
  return config
}
