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

Compiling multiple entry files with reaxt #8

Open
emilingerslev opened this issue Aug 19, 2015 · 4 comments
Open

Compiling multiple entry files with reaxt #8

emilingerslev opened this issue Aug 19, 2015 · 4 comments
Labels

Comments

@emilingerslev
Copy link
Contributor

I got an elixir app where I need multiple react apps. That can be done with different react.render :<target>, but it will stil use the same js file.
Is it somehow possible to make separate js files for different parts of the app?

@awetzel
Copy link
Collaborator

awetzel commented Sep 11, 2015

I am very sorry for the late answer, yes of course it is possible, using webpack.config you can customize "entries" as you want. (see http://webpack.github.io/docs/multiple-entry-points.html)

For instance replace entry: "./index" with

 entry: {
        lib1: "./index1",
        lib2: "./index2"
}

Then the require() and codes of index1 and index2 will be compiled in each file separatedly. The only (big) constraint is that reaxt will automatically include in all your entries all the react components (files in the "component" dir). So if you want to partition well your code, it is important to not put everything into components.

you can also customize the output file name and directory :

  output: {
    path: '/some/output/dir',
    filename: '[name].[hash].js', 
    publicPath: '/myprefix/'
  }

Then you only have to include WebPack.file_of(:lib1) and WebPack.file_of(:lib2) (maybe "lib2, not sure, please test), in your html file and serve the output dir with the correct prefix :

plug Plug.Static, at: "/myprefix", from: "/some/output/dir"

@emilingerslev
Copy link
Contributor Author

I know it is with time :) I'll look into testing this out. I'm not sure what you mean with all components will be included into all entries though?

Does this mean that even if I don't reference the files in the entries it will still be included?

@awetzel
Copy link
Collaborator

awetzel commented Sep 11, 2015

Yes exactly, to be clear, the entry client_entry_addition.js is added to every entries by reaxt. and this file contains require("./../../components/"+module) in order to make reaxt work. https://github.com/awetzel/reaxt/blob/master/priv/commonjs_reaxt/client_entry_addition.js#L8

So that makes all components to be included in all entries, see :
http://webpack.github.io/docs/configuration.html#automatically-created-contexts-defaults-module-xxxcontextxxx

@emilingerslev
Copy link
Contributor Author

Is it then beyond the scope of Reaxt to make multiple entries each with their own separate group of components?

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

No branches or pull requests

3 participants