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

Sometimes gatsby build doesn't minify the commons-*.js file #2877

Closed
resir014 opened this issue Nov 10, 2017 · 5 comments · May be fixed by tejzpr/gatsby#61
Closed

Sometimes gatsby build doesn't minify the commons-*.js file #2877

resir014 opened this issue Nov 10, 2017 · 5 comments · May be fixed by tejzpr/gatsby#61

Comments

@resir014
Copy link
Contributor

  • Gatsby version: gatsby 1.9.106, gatsby-cli 1.1.20
  • Node version: 8.9.0
  • OS: Windows 10 (x64)

I've brought up this issue on the Reactiflux chat the other day, but I'm going to put it as an issue here since it's potentially an issue on both Gatsby and Netlify.

On some occasions,gatsby build doesn't generate a minified commons-*.js file:

image

This could sometimes result in the React Devtools saying that I'm not running a minified build of React whenever I deploy to Netlify with Continuous Deployment:

image

Running gatsby build and manually deploying everything to Netlify will cause React Devtools to behave, however the resulting commons-*.js file remains unminified.

@sebastienfi
Copy link
Contributor

See my post here, maybe it helps #2771

@resir014
Copy link
Contributor Author

@sebastienfi ah, thanks a lot! I can close this as a duplicate then.

@resir014
Copy link
Contributor Author

resir014 commented Nov 10, 2017

Reopening this to post my solution.

gatsby-node.js

exports.modifyWebpackConfig = ({ config, stage }) => {
  if (stage === 'build-javascript') {
    // Temporary workaround.
    // Here we override the Webpack plugin during the `build-javascript` stage to make everything
    // compile down to es5 - turns out Webpack 1's UglifyJsPlugin doesn't like that we have some
    // ES6 stuff littered in our final bundle...
    config.loader('typescript', {
      test: /\.tsx?$/,
      loaders: ['ts-loader']
    })
  }
}

tsconfig.json (note the es5 compile target)

{
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "module": "commonjs",
    "target": "es5",
    "jsx": "react",
    "lib": ["dom", "esnext"]
  },
  "include": [
    "./src/**/*"
  ]
}
@Cammisuli
Copy link

I tried to follow the advice from @resir014's post, but I kept getting Cannot read property 'initial' of undefined.

So, I found the proper solution for me, and maybe this could help others in the future. In the plugin section of gatsby-config.js, specify the typescript target in compilerOptions to 'es5'

{
  resolve: "gatsby-plugin-typescript",
  options: {
    compilerOptions: {
      target: 'es5'
    }
  }
}
@resir014
Copy link
Contributor Author

resir014 commented Feb 6, 2018

@Cammisuli Please update gatsby-plugin-typescript. This whole issue is fixed on #3369, so the workaround is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants