backpack icon indicating copy to clipboard operation
backpack copied to clipboard

CLI options (--entry)

Open dralletje opened this issue 8 years ago • 10 comments

Hey! I really love how easy backpack makes writing scripts and servers :D

One thing that I would like to see is the ability to provide some options when running backpack. I know it is mainly build to run "a project" now, but when writing scripts I sometimes want to run specific files to test them out or bootstrap something quickly.

I suggest adding a --entry <file> option, that would... use a different entry file :D

If this is something you think would be cool (😎) I'd love to make a PR for it!

dralletje avatar Jan 15 '17 16:01 dralletje

What about using the main field in package.json?

benjick avatar Jan 16 '17 09:01 benjick

@benjick sounds like another good option, but isn't really what I am hoping for :-) Because then you still can't "just run a file" without editing your package.json

dralletje avatar Jan 16 '17 12:01 dralletje

Related, I'm going to be testing out backpack with a project that has multiple entry-points, so using package.json is out...

ericclemmons avatar Feb 17 '17 04:02 ericclemmons

I did this in my backpack.config.js:

module.exports = {
  webpack: (config) => {
    // eslint-disable-next-line no-param-reassign
    config.entry.main = [
      './src/server/index.js',
    ];

    return config;
  },
};

benjick avatar Feb 17 '17 19:02 benjick

POC: https://github.com/pandada8/backpack very rough implementation and need improvement Usage: backpack run xxxx.js -- --extra-options-can-be-pass-to-script

pandada8 avatar Aug 22 '17 17:08 pandada8

@benjick Your method is feasible, but it cannot support multiple entries.

For example, I have both a server and a client in a project, for some reason.

yoyo837 avatar Sep 13 '17 08:09 yoyo837

@yoyo837 You use this for frontend too?

benjick avatar Sep 13 '17 09:09 benjick

@yoyo837 You should use Razzle if you have both a client and server

jaredpalmer avatar Sep 13 '17 13:09 jaredpalmer

@benjick @jaredpalmer No, just http client and server. Two entries.

yoyo837 avatar Sep 13 '17 13:09 yoyo837

Here is how I work with multiple entry-points:

package.json:

"scripts": {
    "backpackEntry1": "cross-env BACKPACK_ENTRY=entry1 backpack dev",
    "backpackEntry2": "cross-env BACKPACK_ENTRY=entry2 backpack dev"
  },

backpack.config.js:

module.exports = {
  webpack: (config, options, webpack) => {
    config.entry.main = './server/entry.js';
    return config;
  }
}

server/entry.js:


const BACKPACK_ENTRY_MAP = {
  entry1: () => {
    require('./entry1')();
  },
  entry2: () => {
    require('./entry2')();
  }
};

const runEntryCommand = () => {
  console.log(process.env.BACKPACK_ENTRY);
  const entry = process.env.BACKPACK_ENTRY;
  const task = BACKPACK_ENTRY_MAP[entry] || BACKPACK_ENTRY_MAP['entry1'];

  task();
}

runEntryCommand();

coolriver avatar Sep 30 '17 07:09 coolriver