Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something wrong when rollup.config.js export an array #7

Open
DeepenLau opened this issue Dec 11, 2017 · 0 comments
Open

Something wrong when rollup.config.js export an array #7

DeepenLau opened this issue Dec 11, 2017 · 0 comments

Comments

@DeepenLau
Copy link

// rollup.config.js
import commonjs    from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import babel       from 'rollup-plugin-babel';
import Replace     from 'rollup-plugin-replace';
import serve       from 'rollup-plugin-serve'
import livereload  from 'rollup-plugin-livereload'
import uglify      from 'rollup-plugin-uglify';
import html        from 'rollup-plugin-fill-html';

const isProduction = process.env.NODE_ENV === 'production'

function setConfig (options) {
  const config = {
    input: options.input,
    output: {
      file: isProduction ? options.output.minifyFilename : options.output.filename,
      format: 'iife',
      sourcemap: isProduction ? false : 'inline'
    },
    plugins: [
      babel({
        exclude: 'node_modules/**' // only transpile our source code
      }),
      nodeResolve(),
      commonjs({
        namedExports: {
          'node_modules/react/index.js': ['Children', 'Component', 'createElement']
        }
      }),
      Replace({
        'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
      }),
      html({
        template: options.html.template,
        filename: options.html.filename
      })
      // browsersync({server: 'home'})
    ]
  }

  if (isProduction) {
    config.plugins = config.plugins.concat([
      // hash({
      // 	dest: options.output.minifyFilename
      // }),
      uglify({
        compress: {
          warnings: false,
          drop_console: true
        },
        output: {
          comments: false
        }
      })
    ])
  } else {
    // config.plugins = config.plugins.concat([
    //   serve({
    //     open: true,
    //     historyApiFallback: true,
    //     contentBase: ['./dist'],
    //     port: 8080,
    //   }),
    //   livereload()
    // ])
  }

  return config
}

const configs = [
  setConfig({
    input: './src/auth/main.js',
    output: {
      minifyFilename: './dist/auth/index.min.[hash].js',
      filename: './dist/auth/index.js'
    },
    html: {
      template: './src/auth/index.html',
      filename: 'auth/index.html',
    }
  }),
  setConfig({
    input: './src/home/main.js',
    output: {
      minifyFilename: './dist/home/index.min.[hash].js',
      filename: './dist/home/index.js'
    },
    html: {
      template: './src/home/index.html',
      filename: 'home/index.html',
    }
  })
]

export default configs

I got this in auth/index.html
image

and i got this in home/index.html
image

By the way, the path is not my expectation
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant