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

[RFC] Route Based Code Splitting #136

Closed
1 of 5 tasks
thescientist13 opened this issue Jul 31, 2019 · 2 comments · Fixed by #265
Closed
1 of 5 tasks

[RFC] Route Based Code Splitting #136

thescientist13 opened this issue Jul 31, 2019 · 2 comments · Fixed by #265
Assignees
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) P0 Critical issue that should get addressed ASAP RFC Proposal and changes to workflows, architecture, APIs, etc v0.6.0 Code Splitting + Markdown enhancements
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Jul 31, 2019

Type of Change

  • New Feature Request (RFC)
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

As it stands now it looks like Greenwood only creates on index.js. Would like to look into how we can possibly do route based code splitting, or I guess in the context of this project, template based code splitting?
Screen Shot 2019-09-18 at 7 59 54 AM

Details

In particular this is a potential concern until larger projects can be tested because if ALL the content / code ends up in index.js then it will absolutely crush larger projects even though currently the Greenwood website scores well.

Ideally we should be able to configure this all through webpack.
https://webpack.js.org/plugins/split-chunks-plugin/

We should also want to handle / consider splitting out vendor code into it's own chunk too.

@thescientist13 thescientist13 added the RFC Proposal and changes to workflows, architecture, APIs, etc label Jul 31, 2019
@thescientist13 thescientist13 added this to the MVP milestone Jul 31, 2019
@thescientist13 thescientist13 self-assigned this Sep 18, 2019
@hutchgrant
Copy link
Member

hutchgrant commented Nov 15, 2019

lit-redux-router allows for lazy loading components, I know because I contributed that functionality to that project(only time I've been able to say that). With webpack, we can use dynamic imports

app.js

import { navigate } from 'lit-redux-router';
import store from './store.js';

class MyApp extends LitElement {
  render() {
    return html`
      <div class="app-content">
        <lit-route
          path="/docs"
          component="my-docs"
          .resolve="${() => import('./docs.js')}"
          loading="my-loading"
        ></lit-route>
      </div>
    `;
  }
}
customElements.define('my-app', MyApp);

class MyLoading extends LitElement {
  render() {
    return html`
      <style>
        h1 {
          margin-top: 0;
          margin-bottom: 16px;
        }
      </style>
      <h1>Loading...</h1>
    `;
  }
}

This will display a loading component, while we wait for the new page component to resolve.

webpack.config.common.js

    output: {
      filename: '[name].bundle.js',
      chunkFilename: '[name].bundle.js',
      publicPath: 'dist/',
      path: path.resolve(__dirname, 'dist'),
    },

This will split our bundle into chunks.

In order to use that, we would have to adjust the scaffold to dynamically import each page component in addition to webpack.

@thescientist13
Copy link
Member Author

thescientist13 commented Nov 17, 2019

Yeah, was thinking something like that as well but maybe grouped by top level route, e.g. in our case a bundle for:

  • vendor / common / shared
  • home
  • docs
  • about
  • etc

Will be really exciting to implement this to coincide with data in / data out combo. 🙌

@thescientist13 thescientist13 mentioned this issue Jan 29, 2020
13 tasks
@thescientist13 thescientist13 added the P0 Critical issue that should get addressed ASAP label Apr 24, 2020
@thescientist13 thescientist13 added CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) labels May 3, 2020
@thescientist13 thescientist13 added the v0.6.0 Code Splitting + Markdown enhancements label Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) P0 Critical issue that should get addressed ASAP RFC Proposal and changes to workflows, architecture, APIs, etc v0.6.0 Code Splitting + Markdown enhancements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants