Upgrade to webpack 3#14315
Conversation
b0a0d73 to
1761e87
Compare
1761e87 to
eead1e4
Compare
|
@jbudz do you know what impact the new |
|
We chown the whole optimize dir here so I think we'll be good. If an optimize is triggered as a different user we'll have perm issues, but it'll be consistent with the existing permission issues |
|
We may want to create an empty directory so we don't run into #7458, but I don't think it'll have any benefit if we don't have the filenames beforehand. I think the right way to go is to put the optimize step behind a flag so it's only ran by the kibana server (and not the plugin installer, possibly only for packages), and thus the kibana user. For reference, the issue I mentioned in the above comment is #8818. sorry for all the words. tldr no regression, possible permission issues. |
| loader: 'jade-loader' | ||
| }, | ||
| { | ||
| test: /\.json$/, |
There was a problem hiding this comment.
This can be removed
https://webpack.js.org/guides/migrating/#json-loader-is-not-required-anymore
| query: { | ||
| config: require.resolve('./postcss.config') | ||
| } | ||
| const devtool = this.sourceMaps; |
There was a problem hiding this comment.
A lot of these are only used once. Any reason for the assignment? To me, it doesn't appear to improve readability.
There was a problem hiding this comment.
I really just wanted to know what this.* properties are being used for what settings, which I think this communicates, but I'm fine removing the renaming if you prefer.
| modules: [ | ||
| 'webpackShims', | ||
| 'node_modules', | ||
| resolve(contextDir, 'webpackShims'), |
There was a problem hiding this comment.
I believe these two absolute paths are redundant.
There was a problem hiding this comment.
Actually, they ensure that plugins will be able to use the webpackShims and node_modules from Kibana even when they are defined outside of the Kibana source directory.
There was a problem hiding this comment.
Don't we create a symlink inside the plugins directory for those?
There was a problem hiding this comment.
No, but even if we did webpack will use the real path of the module, not the link, to find the node_modules/webpackShims directories to match node.js functionality
| }, | ||
| ], | ||
| }, | ||
| ...postLoaders.map(loader => ({ |
There was a problem hiding this comment.
Looks like postLoaders were removed.
https://webpack.js.org/guides/migrating/#module-preloaders-and-module-postloaders-were-removed-
There was a problem hiding this comment.
Yeah, which is why this adds enforce: 'post' to each loader definition.
|
@spalger, this ready for another look? |
|
@tylersmalley yes sir |
|
I have published snapshots of this branch: Then, with one of the builds, installed an X-Pack snapshot In addition to taking longer than expected (almost 6 minutes), it also produced an error: |
2913568 to
a590af4
Compare
|
As Spencer pointed out on Slack, my issue was caused by not running X-Pack off of the corresponding branch. Regarding the plugin installation/optimize time, it's consistent with master. However, that time seems to have ballooned at some point. We're now looking at ~8-9 minutes to install X-Pack on my machine. |
kimjoar
left a comment
There was a problem hiding this comment.
LGTM. A couple nitpicks.
| { | ||
| loader: 'css-loader', | ||
| options: { | ||
| importLoaders: 1 + preProcessors.length, |
There was a problem hiding this comment.
Maybe add a comment explaining why 1 + len?
| if (env !== 'production') { | ||
| return []; | ||
| return webpackMerge(commonConfig, { | ||
| externals: { |
There was a problem hiding this comment.
nitpick, maybe pull in the comment above into:
if (this.env.context.env === 'development') {
return webpackMerge(commonConfig, {
// In the test env we need to add react-addons (and a few other bits) for the
// enzyme tests to work.
// https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md
externals: {
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': true,
}
});
}| alias: transform(pkg.dependencies, function (aliases, version, name) { | ||
| if (name.endsWith('-loader')) { | ||
| aliases[name] = require.resolve(name); | ||
| alias: Object.keys(pkg.dependencies || {}).reduce((acc, key) => { |
There was a problem hiding this comment.
I removed resolveLoader entirely and the build succeeded. Not sure if this block is needed anymore? If it's still needed, maybe add a comment that clarifies its purpose?
There was a problem hiding this comment.
You're right, I couldn't find the docs for this at first but webpack 2 changed the way loaders are resolved in the module rules: https://webpack.js.org/configuration/module/#useentry
In webpack 1 the loaders defined here were resolved relative to the file they were going to load, which meant that plugins in other projects could accidentally overwrite the loaders Kibana was trying to use, which is why the aliases were used to enforce proper resolution.
In webpack 2 loaders are now resolved relative to the webpackConfig.context, which is set to the root of the Kibana repo.
In webpack 1 the loaders defined here were resolved relative to the file they were going to load, which meant that plugins in other projects could accidentally overwrite the loaders Kibana was trying to use, which is why the aliases were used to enforce proper resolution. In webpack 2 loaders are now resolved relative to the webpackConfig.context, which is set to the root of the Kibana repo. See https://webpack.js.org/configuration/module/#useentry
|
@spalger I think we should backport this to 6.x. We should learn more about the problems this does or does not introduce quicker since a lot of manual QA is and will be done on 6.1, and backporting it early means we're not caught in a situation where we need to track down a long line of related PRs that may have been fixing bugs that this introduced, since we'll be backporting them as they are fixed. I think if there were truly glaring problems outstanding with this change, we would have caught them by now. |
|
👍 @epixa |
* [timelion] remove last remaining amd modules * [eslint-config-kibana] remove env.amd * [webpack] use absolute loader names * [webpack] remove absolute node_modules/ imports * [webpack] upgrade to webpack 3 * [uiFramework] make webpack build compatible with v3 * [eslint-import-resolver] use elastic/eslint-import-resolver-kibana#21 * [baseOptimizer] don't break when pkg has no dependencies * [optimize] remove unnecessary json-loader * [optimize] remove local references to webpack vars * [eslint] upgrade to eslint-import-resolver-kibana 0.9.0 * [baseOptimizer] comment tweaks * [baseOptimizer] remove loader pinning In webpack 1 the loaders defined here were resolved relative to the file they were going to load, which meant that plugins in other projects could accidentally overwrite the loaders Kibana was trying to use, which is why the aliases were used to enforce proper resolution. In webpack 2 loaders are now resolved relative to the webpackConfig.context, which is set to the root of the Kibana repo. See https://webpack.js.org/configuration/module/#useentry * [webpack] rely on kibana webpack shims before checking node_modules (cherry picked from commit f60639f)
* [timelion] remove last remaining amd modules * [eslint-config-kibana] remove env.amd * [webpack] use absolute loader names * [webpack] remove absolute node_modules/ imports * [webpack] upgrade to webpack 3 * [uiFramework] make webpack build compatible with v3 * [eslint-import-resolver] use elastic/eslint-import-resolver-kibana#21 * [baseOptimizer] don't break when pkg has no dependencies * [optimize] remove unnecessary json-loader * [optimize] remove local references to webpack vars * [eslint] upgrade to eslint-import-resolver-kibana 0.9.0 * [baseOptimizer] comment tweaks * [baseOptimizer] remove loader pinning In webpack 1 the loaders defined here were resolved relative to the file they were going to load, which meant that plugins in other projects could accidentally overwrite the loaders Kibana was trying to use, which is why the aliases were used to enforce proper resolution. In webpack 2 loaders are now resolved relative to the webpackConfig.context, which is set to the root of the Kibana repo. See https://webpack.js.org/configuration/module/#useentry * [webpack] rely on kibana webpack shims before checking node_modules (cherry picked from commit f60639f)
* [timelion] remove last remaining amd modules * [eslint-config-kibana] remove env.amd * [webpack] use absolute loader names * [webpack] remove absolute node_modules/ imports * [webpack] upgrade to webpack 3 * [uiFramework] make webpack build compatible with v3 * [eslint-import-resolver] use elastic/eslint-import-resolver-kibana#21 * [baseOptimizer] don't break when pkg has no dependencies * [optimize] remove unnecessary json-loader * [optimize] remove local references to webpack vars * [eslint] upgrade to eslint-import-resolver-kibana 0.9.0 * [baseOptimizer] comment tweaks * [baseOptimizer] remove loader pinning In webpack 1 the loaders defined here were resolved relative to the file they were going to load, which meant that plugins in other projects could accidentally overwrite the loaders Kibana was trying to use, which is why the aliases were used to enforce proper resolution. In webpack 2 loaders are now resolved relative to the webpackConfig.context, which is set to the root of the Kibana repo. See https://webpack.js.org/configuration/module/#useentry * [webpack] rely on kibana webpack shims before checking node_modules
Upgrades the optimizer to use webpack 3. Also introduces cache-loaders, which make builds much more efficient by storing loader caches on disk, in the
optimize/.cachedirectory.This also helps greatly with the memory issues people have been experiencing. I recommend that we just merge this into master, try it out for a little while, and see how it goes.
The only real departure from webpack 2 is the fact that it no longer checks the root of the Kibana repo when trying to resolve modules. It's not clear why it was ever doing this, but it seems that the only place that was using this feature was webpackShims, so they now use relative imports to load directly from the node_modules directory.