[canvas] Improve plugin pre-build (#25267) (#25569)

Fixes https://github.com/elastic/kibana/issues/23552

Extends the webpack config used to pre-build `x-pack/plugins/canvas/canvas_plugins_src` so that it does a couple things:
 - use the "browser" and "main" fields when defined by packages, this allows the already transpiled output of packages like `@elastic/eui` to be used rather than rebuilding from source
 - use the `@kbn/babel-preset/webpack_preset` for babel-loader
 - include all errors in the log output when an error occurs
This commit is contained in:
Spencer 2018-11-12 19:35:07 -08:00 committed by GitHub
parent 1593c10bc6
commit 854d1882bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 42 additions and 54 deletions

View file

@ -23,6 +23,10 @@ module.exports = {
'functions/common/all': path.join(sourceDir, 'functions/common/register.js'),
'types/all': path.join(sourceDir, 'types/register.js'),
},
// there were problems with the node and web targets since this code is actually
// targetting both the browser and node.js. If there was a hybrid target we'd use
// it, but this seems to work either way.
target: 'webworker',
output: {
@ -33,6 +37,7 @@ module.exports = {
resolve: {
extensions: ['.js', '.json'],
mainFields: ['browser', 'main'],
},
plugins: [
@ -47,8 +52,10 @@ module.exports = {
});
this.plugin('done', function(stats) {
if (stats.compilation.errors && stats.compilation.errors.length && !isWatch)
throw stats.compilation.errors[0];
if (!stats.hasErrors()) return;
const errorMessage = stats.toString('errors-only');
if (isWatch) console.error(errorMessage);
else throw new Error(errorMessage);
});
},
new CopyWebpackPlugin([
@ -62,64 +69,15 @@ module.exports = {
module: {
rules: [
// There's some React 15 propTypes funny business in EUI, this strips out propTypes and fixes it
{
test: /(@elastic[\/\\]eui|moment)[\/\\].*\.js$/,
test: /\.js$/,
exclude: [/node_modules/],
loaders: 'babel-loader',
options: {
babelrc: false,
presets: [
'react',
[
'env',
{
targets: {
node: 'current',
},
},
],
],
plugins: [
'transform-react-remove-prop-types', // specifically this, strips out propTypes
'pegjs-inline-precompile',
'transform-object-rest-spread',
'transform-async-to-generator',
'transform-class-properties',
[
'inline-react-svg',
{
ignorePattern: 'images/*',
svgo: {
plugins: [{ cleanupIDs: false }, { removeViewBox: false }],
},
},
],
],
presets: [require.resolve('@kbn/babel-preset/webpack_preset')],
},
},
{
test: /\.js$/,
loaders: 'babel-loader',
options: {
plugins: [
'transform-object-rest-spread',
'transform-async-to-generator',
'transform-class-properties',
],
presets: [
'react',
[
'env',
{
targets: {
node: 'current',
},
},
],
],
},
exclude: [/node_modules/],
},
{
test: /\.(png|jpg|gif|jpeg|svg)$/,
loaders: ['url-loader'],