[6.x] [optimizer] allow prod optimizations when running source (#20174) (#20175)

Backports the following commits to 6.x:
 - [optimizer] allow prod optimizations when running source  (#20174)
This commit is contained in:
Spencer 2018-06-22 19:47:31 -07:00 committed by GitHub
parent 5196b2d768
commit 229e336dc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 47 deletions

View file

@ -286,58 +286,59 @@ export default class BaseOptimizer {
},
};
if (!IS_KIBANA_DISTRIBUTABLE) {
return webpackMerge(commonConfig, {
module: {
rules: [
{
resource: createSourceFileResourceSelector(/\.tsx?$/),
use: maybeAddCacheLoader('typescript', [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
onlyCompileBundledFiles: true,
compilerOptions: {
sourceMap: Boolean(this.sourceMaps),
target: 'es5',
module: 'esnext',
}
// we transpile typescript in the optimizer unless we are running the distributable
const transpileTsConfig = {
module: {
rules: [
{
resource: createSourceFileResourceSelector(/\.tsx?$/),
use: maybeAddCacheLoader('typescript', [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
onlyCompileBundledFiles: true,
compilerOptions: {
sourceMap: Boolean(this.sourceMaps),
target: 'es5',
module: 'esnext',
}
}
]),
}
]
},
}
]),
}
]
},
stats: {
// when typescript doesn't do a full type check, as we have the ts-loader
// configured here, it does not have enough information to determine
// whether an imported name is a type or not, so when the name is then
// exported, typescript has no choice but to emit the export. Fortunately,
// the extraneous export should not be harmful, so we just suppress these warnings
// https://github.com/TypeStrong/ts-loader#transpileonly-boolean-defaultfalse
warningsFilter: /export .* was not found in/
},
stats: {
// when typescript doesn't do a full type check, as we have the ts-loader
// configured here, it does not have enough information to determine
// whether an imported name is a type or not, so when the name is then
// exported, typescript has no choice but to emit the export. Fortunately,
// the extraneous export should not be harmful, so we just suppress these warnings
// https://github.com/TypeStrong/ts-loader#transpileonly-boolean-defaultfalse
warningsFilter: /export .* was not found in/
},
resolve: {
extensions: ['.ts', '.tsx'],
},
resolve: {
extensions: ['.ts', '.tsx'],
},
};
// 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: {
'mocha': 'mocha',
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': true,
}
});
}
// We need to add react-addons (and a few other bits) for enzyme to work.
// https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md
const supportEnzymeConfig = {
externals: {
'mocha': 'mocha',
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': true,
}
};
return webpackMerge(commonConfig, {
// in production we set the process.env.NODE_ENV and uglify our bundles
const productionConfig = {
plugins: [
new webpack.DefinePlugin({
'process.env': {
@ -352,7 +353,17 @@ export default class BaseOptimizer {
mangle: false
}),
]
});
};
return webpackMerge(
commonConfig,
IS_KIBANA_DISTRIBUTABLE
? {}
: transpileTsConfig,
this.uiBundles.isDevMode()
? supportEnzymeConfig
: productionConfig
);
}
failedStatsToError(stats) {

View file

@ -100,6 +100,10 @@ export class UiBundlesController {
}
}
isDevMode() {
return this._env === 'development';
}
getWebpackPluginProviders() {
return this._webpackPluginProviders || [];
}