Skip to content

isFramework in commonsChunkPlugin does not work properly on windows #3937

@greglobinski

Description

@greglobinski

Description

gatsby build creates different bundles on my localhost (windows) and different on server (Netlify).

Environment

Gatsby version: 1.9.169
Node.js version: 8.7.0
Operating System: win 7

Actual result

As described here #746 (comment)
Gatsby in webpack.config.js uses function as a parameter for minChunk option of commonsChunkPlugin. Inside the function is a tester isFramework.

The RegExp pattern in the tester does not test positively on Windows dev environment (different path separator), so gatsby build generates different bundles on my localhost (windows) and different on server. On localhost the packages of vendorModuleList are not moved to the commons bundle as they should (doesn't matter how often they occur in chunks).

current state of the function

    const isFramework = some(
        vendorModuleList.map(vendor => {
            const regex = new RegExp(`/node_modules/${vendor}/.*`, `i`)
            return regex.test(module.resource)
        })
    )

a small change in the RegExp pattern fixes the problem:

    const isFramework = some(
        vendorModuleList.map(vendor => {
            const regex = new RegExp(`[\\\\/]node_modules[\\\\/]${vendor}[\\\\/].*`, `i`)
            return regex.test(module.resource)
        })
    )

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