Skip to content

webpack dynamic modules #362

Closed
Closed

Description

@mr47

It's seem that current webpack config don't support require.ensure

Simple component with gl-react

//@flow

import React from 'react'
import ReactDOM from 'react-dom'
import BaseTemplate from '../layout/baseTemplate'

export default class extends React.Component {
    node: any;
    static async getInitialProps({ req }): any {
        const isServer = !!req;
        return {
            isServer: isServer
        }
    }
    componentDidMount(){
        require.ensure([], () => {
            const { Shaders, Node, GLSL } = require("gl-react");
            const { Surface } = require("gl-react-dom");
            const shaders = Shaders.create({
                helloGL: {
                    // This is our first fragment shader in GLSL language (OpenGL Shading Language)
                    // (GLSL code gets compiled and run on the GPU)
                    frag: GLSL`
                        precision highp float;
                        varying vec2 uv;
                        void main() {
                          gl_FragColor = vec4(uv.x, uv.y, 0.5, 1.0);
                        }
                    `
                    // the main() function is called FOR EACH PIXELS
                    // the varying uv is a vec2 where x and y respectively varying from 0.0 to 1.0.
                    // we set in output the pixel color using the vec4(r,g,b,a) format.
                    // see GLSL_ES_Specification_1.0.17
                }
            });
            ReactDOM.render((
                <Surface width={300} height={300}>
                    <Node shader={shaders.helloGL} />
                </Surface>
            ), this.node);
        });
    }
    render(): any {
        return (
            <div ref={(node) => this.node = node}></div>
        );
    }
}

It's work in dev but when i try to next build and then next start get error that chunk not find
It's name 3.3 and it's located in .next folder 😕

Thanks!

UPD: pull request for fix open

Activity

  1. added a commit that references this issue on Dec 8, 2016
  2. rauchg commented on Dec 8, 2016

    @rauchg
    Member

    I'd love to have a simple solution for dynamic imports, especially with the more definitive ES APIs coming

  3. mr47 commented on Dec 8, 2016

    @mr47
    ContributorAuthor

    @rauchg currently using webpack 1.x we still can use require.ensure, later we can switch to System.import on webpack 2 (require.ensure will still supported)

  4. mr47 commented on Dec 8, 2016

    @mr47
    ContributorAuthor

    @rauchg I have idea, it's can look like this :

    <Require src="./../components/test">
        <Client>
            {'Hello from Client!'}
            <ProxyComponent isClient={true} ...otherOptions />
        </Client>
        <Server>
            {'Hello from Server!'}
            <ProxyComponent isServer={true} ...otherOptions/>
        </Server>
    </Require>

    or if we want just make a lazy load component

     <Require src="gl-react"/>

    PS: It's still random thoughts

  5. added a commit that references this issue on Dec 15, 2016
  6. mr47 commented on Dec 21, 2016

    @mr47
    ContributorAuthor

    @arunoda, @rauchg updated to master version of next, still have problem with require.ensure.
    In dev mode all works just fine.
    In prod mode after next build chunk are created but not served as expected.
    For this i still see solution to set a custom chunkFilename, and serve route like
    [name].[hash:4] so we get lazy modules support easy and very clean, later on we can think about it more.

    Thanks!

  7. arunoda commented on Dec 21, 2016

    @arunoda
    Contributor

    @mr47 I think it won't as the current state.
    Currently, we haven't looked into what's really going on here of our support for require.ensure.

    Since we open the programmatic API with 2.0 and the webpack config, it allows us to play with these features in the userland.
    If we need some core support it, let's think about doing it for 2.1 or some other releases.

    Keep us updated.

  8. rauchg commented on Jan 10, 2017

    @rauchg
    Member

    Let's move the discussion to #728, because this will be a priority after 2.0

  9. locked as resolved and limited conversation to collaborators on May 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions