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

webpack dynamic modules #362

Closed
mr47 opened this issue Dec 8, 2016 · 7 comments
Closed

webpack dynamic modules #362

mr47 opened this issue Dec 8, 2016 · 7 comments

Comments

@mr47
Copy link
Contributor

mr47 commented Dec 8, 2016

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

@mr47
Copy link
Contributor Author

mr47 commented Dec 8, 2016

Yes on https://github.com/zeit/next.js/blob/master/server/index.js#L42 we serve only commons.js

mr47 added a commit to mr47/next.js that referenced this issue Dec 8, 2016
@rauchg
Copy link
Member

rauchg commented Dec 8, 2016

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

@mr47
Copy link
Contributor Author

mr47 commented Dec 8, 2016

@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)

@mr47
Copy link
Contributor Author

mr47 commented Dec 8, 2016

@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

arunoda pushed a commit that referenced this issue Dec 15, 2016
* fixed bug #362, also set chunks names

* set simple solution for minChunks

* revert in favor of #310
@mr47
Copy link
Contributor Author

mr47 commented Dec 21, 2016

@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!

@arunoda
Copy link
Contributor

arunoda commented Dec 21, 2016

@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.

@rauchg
Copy link
Member

rauchg commented Jan 10, 2017

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

@rauchg rauchg closed this as completed Jan 10, 2017
@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
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