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

Build Single File for Distribution #1452

Closed
bryandbor opened this issue Jan 26, 2017 · 4 comments
Closed

Build Single File for Distribution #1452

bryandbor opened this issue Jan 26, 2017 · 4 comments

Comments

@bryandbor
Copy link

I'm building a small app that will need to act as a library for a client. They will need to pull a single JS and CSS file from me and then initialize my code using their own JS files. Therefore, I need to find a way to build my project into a single JS and a single CSS file. Is there a way to build with this in mind?

Example:
index.html

<script src="my_app.com/my_library_file.js></script>
<link rel="stylesheet" type="text/css" href="my_app.com/my_library_style.css"></link>

<div id="root"></div> <!-- will be used as React root when client initializes library -->

index.js

// after page loaded
my_library.init({
  //options here
});

I am not worried about giving these files pleasant names, I am only concerned with building them into single files or automating the pulling of the other files of a build from my server.

@gaearon
Copy link
Contributor

gaearon commented Jan 26, 2017

Isn't npm run build providing you with a single file?

@bryandbor
Copy link
Author

I was under the impression that npm run build would commonly split the build into multiple files in order to give your code the "Just in time" code feel (pulling in code only if/when it is necessary to enable certainly functionality)? If I'm wrong, then this is a non-issue. :)

@gaearon
Copy link
Contributor

gaearon commented Jan 27, 2017

No, by default it bundles everything into a single JS file. You do have an option of code splitting (by calling require.ensure), but it's not the default.

@gaearon gaearon closed this as completed Jan 27, 2017
@piotr-cz
Copy link
Contributor

piotr-cz commented Jun 8, 2017

When there is a custom stylesheet specified in the index.html file, it's not included in the bundle built for production.

Just import it from the src/index.css file (make sure you import index.css before App like here: #2470)

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants