-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
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 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. |
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:
|
Could someone else try and compare? I will try again later, maybe somehow related to my machine.
I wanted to have good defaults for people who deploy apps. Looking at webpack 4 it seems to be as easy as passing
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?
It would be fine with me to fix it. Can we keep it as a separate issue? |
I can give it a try. Is measuring the time to execute |
That's what I did and should be a good test. Also, please test if the behavior of |
I get similar results as @akosyakov : 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. |
Please make sure that you have set |
ok, i will look into it now, with the watch my bad i rebuilt the wrong package, works nicely! |
Thanks for the tip. @ishitatsuyuki . Running For |
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 |
@@ -104,7 +105,6 @@ module.exports = { | |||
}, | |||
devtool: 'source-map', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
I think we just should add |
dev-packages/cli/README.md
Outdated
@@ -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 |
There was a problem hiding this comment.
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
.
dev-packages/cli/README.md
Outdated
|
||
In order to rebuild on each change: | ||
|
||
theia build --watch | ||
NODE_ENV=development theia build --watch |
There was a problem hiding this comment.
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
examples/electron/package.json
Outdated
@@ -40,7 +40,7 @@ | |||
"prepare": "yarn run clean && yarn build", | |||
"clean": "theia clean", | |||
"build": "theia build", |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
Perhaps, I should have asked it here instead of the task. Why is the |
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
db04472
to
d182f26
Compare
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" | ||
}); |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ishitatsuyuki thank you!
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