Skip to content

Commit

Permalink
[optimizer] allow prod optimizations when running source (#20174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored Jun 22, 2018
1 parent 65ce9f0 commit 8fc0fca
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 47 deletions.
105 changes: 58 additions & 47 deletions src/optimize/base_optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand All @@ -352,7 +353,17 @@ export default class BaseOptimizer {
mangle: false
}),
]
});
};

return webpackMerge(
commonConfig,
IS_KIBANA_DISTRIBUTABLE
? {}
: transpileTsConfig,
this.uiBundles.isDevMode()
? supportEnzymeConfig
: productionConfig
);
}

failedStatsToError(stats) {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/ui_bundles/ui_bundles_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export class UiBundlesController {
}
}

isDevMode() {
return this._env === 'development';
}

getWebpackPluginProviders() {
return this._webpackPluginProviders || [];
}
Expand Down

0 comments on commit 8fc0fca

Please sign in to comment.