// Rollup plugins
import postcss from 'rollup-plugin-postcss';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import dependencies from './dependencies';
import clear from 'rollup-plugin-clear';
import replace from 'rollup-plugin-replace';

process.env.BABEL_ENV = 'production';
process.env.NODE_ENV = 'production';

const config = {
  input: {
    index: 'src/entry.js',
  },
  output: {
    dir: 'umd',
    format: 'umd',
    sourcemap: false,
    entryFileNames: 'micro-components.js',
    exports: 'named',
    name: 'microComponents',
    globals: dependencies,
  },
  plugins: [
    clear({
      targets: ['umd'],
    }),
    postcss({
      // modules: true, // 增加 css-module 功能
      extensions: ['.less', '.css'],
      use: [
        [
          'less',
          {
            javascriptEnabled: true,
          },
        ],
      ],
      inject: true,
      extract: true,
    }),
    resolve(),
    replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
    commonjs({
      include: ['node_modules/**'],
    }),
    babel({ exclude: 'node_modules/**', babelHelpers: 'bundled' }),

    // process.env.NODE_ENV === 'production' && uglify(), //压缩仅支持es5
  ],
  external: (id) => {
    // console.log(id)
    console.log(id);
    return Object.keys(dependencies).some((e) => id === e);
  },
};

export default config;
