import postcss from 'rollup-plugin-postcss';
import clear from 'rollup-plugin-clear';
import basePlugin from './rollupBasePluginConfig';
import dependencies from './dependencies';

const createStyleConfig = (moduleName, dir) => ({
  input: `src/${dir}/${moduleName}/index.js`,
  output: {
    file: `garbage/${moduleName}/index.js`,
    format: 'esm',
    sourcemap: true
  },
  plugins: [
    clear({
      targets: ['garbage']
    }),
    // css 处理，暂时没有加插件
    postcss({
      // modules: true, // 增加 css-module 功能
      extensions: ['.less', '.css'],
      use: [
        [
          'less',
          {
            javascriptEnabled: true
          }
        ]
      ],
      // 样式输出到 createModuleConfig 创建的模块文件夹下
      extract: `style/../../../es/${moduleName}/style/index.css`
    }),

    ...basePlugin
  ],
  external: id => Object.keys(dependencies).some(e => id.indexOf(e) === 0)
});

export default createStyleConfig;
