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

Migrate to webpack 4 and implement production mode #1540

Merged
merged 3 commits into from
Mar 22, 2018

Conversation

ishitatsuyuki
Copy link
Contributor

@ishitatsuyuki ishitatsuyuki commented Mar 18, 2018

HMR doesn't seem possible, as there was no code managing the state transition of the hot update.

Builds are now production by default, --mode development to override.

Close #806
Close #1537

Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
@akosyakov
Copy link
Member

Could you measure the build performance against the current setup in the dev mode? webpack 4 seems to perform worse than what we have now 12 vs 16s for me. Webpack watching does not seem to work and the documentation should be updated to mention NODE_ENV.

As I said migrating to webpack 4 is a separate issue if you just want to fix #1537 you can open a PR with something like https://github.com/TypeFox/monaco-languageclient/blob/557ef39258b05da48c4e403b39465094c3d3f86a/example/webpack.config.js#L36-L56 for the current setup.

@ishitatsuyuki
Copy link
Contributor Author

Sorry, I can't reproduce the slowdown. The build time on my side shrunk from 15s -> 12s, a 20% improvement.

Watch works on my end. I altered a few transpiled files in the git package and it incrementally rebuilt the bundle in <1s.

Also, some questions:

  • Someone asked why we should be production by default. Do you have an argument on that?
  • We currently specify devtool: 'source-map' but webpack's default is eval for dev, none for prod. Would you like to switch to that? Didn't show big speedup on my side though.
  • Maybe we can add progress option too, but the Theia CLI currently pipes the output so control sequences are not outputted, not overwriting but creating a new line.

@akosyakov
Copy link
Member

akosyakov commented Mar 19, 2018

Sorry, I can't reproduce the slowdown. The build time on my side shrunk from 15s -> 12s, a 20% improvement. Watch works on my end. I altered a few transpiled files in the git package and it incrementally rebuilt the bundle in <1s.

Could someone else try and compare? I will try again later, maybe somehow related to my machine.

Someone asked why we should be production by default. Do you have an argument on that?

I wanted to have good defaults for people who deploy apps. Looking at webpack 4 it seems to be as easy as passing --mode production: https://www.valentinog.com/blog/webpack-4-tutorial/#webpack_4_production_and_development_mode. It would be fine with me not have development or production by default then. In examples npm scripts, we need to add --mode development.

We currently specify devtool: 'source-map' but webpack's default is eval for dev, none for prod. Would you like to switch to that? Didn't show big speedup on my side though.

In the dev mode, we should be able to debug the original TS code. In the prod mode do we need source maps at all?

Maybe we can add progress option too, but the Theia CLI currently pipes the output so control sequences are not outputted, not overwriting but creating a new line.

It would be fine with me to fix it. Can we keep it as a separate issue?

@marcdumais-work
Copy link
Contributor

Could someone else try and compare?

I can give it a try. Is measuring the time to execute yarn run build in example/browser a valid test for this? Or something else?

@ishitatsuyuki
Copy link
Contributor Author

I can give it a try. Is measuring the time to execute yarn run build in example/browser a valid test for this? Or something else?

That's what I did and should be a good test. Also, please test if the behavior of yarn run watch has changed as well.

@marcdumais-work
Copy link
Contributor

I get similar results as @akosyakov :
master: 14s
with this PR: 19s

It seems that with this PR, webpack is quite slow, in watch mode. Let me test a bit more and I'll post an update.

@ishitatsuyuki
Copy link
Contributor Author

Please make sure that you have set NODE_ENV=development.

@akosyakov
Copy link
Member

ok, i will look into it now, with the watch my bad i rebuilt the wrong package, works nicely!

@marcdumais-work
Copy link
Contributor

Thanks for the tip. @ishitatsuyuki . Running export NODE_ENV=development in my shell first this time, made the watch mode appear as fast as usual.

For yarn run build, your PR seems a bit faster than master in my latest run:
master: 14s
with this PR: 12s (I have seen ~14- ish s on some runs)

@ishitatsuyuki
Copy link
Contributor Author

As defaulting to prod has caused some sort of confusion, I'm going to set dev by default on watch, and still make it prod by default for build. This will make the initial npm install slightly longer, but I guess that's acceptable.

@@ -104,7 +105,6 @@ module.exports = {
},
devtool: 'source-map',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add devtool only if a mode is development

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree. Production doesn't mean errors don't happen, and without sourcemaps it's impossible to report issue with debug info.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Is not it default to webpack 4?
  • What about cases when users not supposed to see the original code?

I don't think we can satisfy everybody here and would like to go with webpack 4 defaults. If someone wants source maps they can create a new webpack config which merges the default and enables source maps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, webpack's default is eval devtool, which results in not very good debugging experience (you can only see generated code). Though, it's probably good to gate on development in this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the dev mode we know what is the good default

Copy link
Member

@akosyakov akosyakov Mar 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishitatsuyuki we discussed it with @svenefftinge, you can leave source maps as is, protection of proprietary extensions is a separate issue

@akosyakov
Copy link
Member

As defaulting to prod has caused some sort of confusion, I'm going to set dev by default on watch, and still make it prod by default for build. This will make the initial npm install slightly longer, but I guess that's acceptable.

I think we just should add --mode development to build and watch npm scripts in examples package.json.

@@ -56,11 +56,15 @@ If you set `next` in your theia config, then Theia will prefer `next` over `late

To build once:

theia build
NODE_ENV=development theia build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be theia build by default, we could add below that to build in dev mode --mode development should be added.

With webpack 4 we should use --mode instead of NODE_ENV.


In order to rebuild on each change:

theia build --watch
NODE_ENV=development theia build --watch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here --mode development

@@ -40,7 +40,7 @@
"prepare": "yarn run clean && yarn build",
"clean": "theia clean",
"build": "theia build",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add --mode development here too, in Theia repo we are never interested in building production-ready artifacts, the same for the browser example

@@ -45,6 +45,7 @@ module.exports = {
path: outputPath
},
target: '${this.ifBrowser('web', 'electron-renderer')}',
mode: development ? 'development' : 'production',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

development should be computed based on mode option instead of NODE_ENV and fall back to production if it is not present, similar to webpack 4 defaults

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that one can send --mode production now and set NODE_ENV to development which installs monaco sources. Although it should not be an issue if we migrate to the latest Monaco.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webpack config is loaded before the arguments get reflected. We may be able to do that if we directly invoke webpack inside JS instead of spawning the CLI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be in process.argv.

@kittaakos
Copy link
Contributor

Builds are now production by default, NODE_ENV=development to override.

Perhaps, I should have asked it here instead of the task. Why is the production mode the default? Does that mean if one builds and starts the application from the source the code will be minified and runs in production mode? Why do not we do the other way around?

@ishitatsuyuki
Copy link
Contributor Author

I think that @akosyakov's argument is that the Theia CLI is mostly used by end users. I'm not sure if it's the case.

@@ -22,15 +22,15 @@ export class WebpackGenerator extends AbstractGenerator {
return this.pck.resolveModulePath(moduleName, path).split(paths.sep).join('/');
}

protected compileWebpackConfig(): string {
protected compileWebpackConfig(mode: string | undefined): string {
return `// @ts-check
const path = require('path');
Copy link
Member

@akosyakov akosyakov Mar 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minimal change is to generate the following into the webpack config:

const { mode }  = yargs.option('mode', {
    description: "Mode to use",
    choices: ["development", "production"],
    default: "production"
});

and pass mode into the configuration.

I don't see why other code should be changed and usage of theia build should stay simple by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is future-proof: we'll no longer be generating config file (and spawning a separate process) after #1552.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will discuss it later whether we want to implement #1552 and how. For now, it is not necessary.

Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
@@ -56,11 +56,15 @@ If you set `next` in your theia config, then Theia will prefer `next` over `late

To build once:

theia build
theia build --mode development
Copy link
Member

@akosyakov akosyakov Mar 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main case: the person creates package.json and use theia-cli to build and start an app, not to develop something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you trying to say? How should I modify this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be just theia build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then what's the point of having watch documented just below? I have clearly indicated what to use for production, there's no need for additional changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i will update docs as the follow up to this PR

description: "Mode to use",
choices: ["development", "production"],
default: "production"
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}).argv is missing, otherwise it returns yargs object

Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishitatsuyuki thank you!

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

Successfully merging this pull request may close these issues.

None yet

4 participants