Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

feat(Connection): add debug option #53

Closed
wants to merge 1 commit into from

Conversation

jakesylvestre
Copy link

@jakesylvestre jakesylvestre commented Oct 19, 2018

Currently, the only way to disable logging is by setting process.env.NODE_ENV to anything but production. This works fine in adonis view environments, but not well for applications that just use Adonis for a backend (since you're not usually setting proccess.env.NODE_ENV in, say, a react application. It's also not to clear how this should be done from the current documentation as is evinced by #50.

This solves both of those issues by introducing a debug option, but defaulting to process.env.NODE_ENV !== 'production' if none is specified. I'll be submitting a peer PR to adonisjs/docs

@jakesylvestre
Copy link
Author

jakesylvestre commented Oct 19, 2018

It looks like this build is failing, I suspect this is an issue with our sauce_labs keys. I can't rerun old tests since I'm not a contributor so I'm going to open a dummy PR to test this theory.

This was referenced Oct 19, 2018
@RomainLanz
Copy link
Member

RomainLanz commented Oct 20, 2018

Hey 👋

The proccess.env.NODE_ENV environment variable is set automatically to production when using any bundler and building for production (what you should do since it's frontend).

This is common for a lot of libraries to add debugging information and remove them at bundling time (React, Vue, etc.)

@thetutlage thetutlage self-requested a review October 20, 2018 08:14
@thetutlage
Copy link
Member

Yeah @RomainLanz is right. The bundler will remove the code inside the if statement when using process.env.NODE_ENV. However, in your changes, the console.log will be hidden, but still bundled inside the production build, increasing the build size

@RomainLanz RomainLanz self-requested a review October 20, 2018 09:02
@iedmrc
Copy link

iedmrc commented Dec 8, 2018

I'm having this problem too. As I mentioned here: https://forum.adonisjs.com/t/disable-websocket-client-console-logs-w-vue/2304

I use Vue.js for frontend and tried every possibility I found. But Adonis.js still prints logs to console.
Package.json

"@vue/cli-service": "^3.0.5",
"@adonisjs/websocket-client": "^1.0.9",
"vue": "^2.5.17",

Some methods I've tried:

// vue.config.js
const webpack = require('webpack');
module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        PRODUCTION: JSON.stringify(true),
        'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
        'NODE_ENV': '"production"',
      })
    ]
  },
  chainWebpack: config => {
    config.plugin('define').tap(definitions => {
      definitions[0] = Object.assign(definitions[0], {
        'process.env.NODE_ENV': '"production"',
        'NODE_ENV': '"production"',
        PRODUCTION: JSON.stringify(true),
      })
      return definitions
    })
  }
}

None of above work.

I think, this PR should be merged (or at least need another way to disable debug) because there are lots of frontend framework and also they change very fast so we may not be able to set process.env.NODE_ENV to something other than 'production' or cannot be sure about it (as in my case). Letting debug to be default doesn't seem right choice.

Thanks!

@RomainLanz
Copy link
Member

Closing this PR since it's not related to this package but the build process you are using.

More information here: #60 (comment)

@RomainLanz RomainLanz closed this Apr 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants