Skip to content
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

Angular build time optimization #4118

Merged
merged 20 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@storybook/core": "4.0.0-alpha.20",
"@storybook/node-logger": "4.0.0-alpha.20",
"angular2-template-loader": "^0.6.2",
"fork-ts-checker-webpack-plugin": "^0.4.9",
"core-js": "^2.5.7",
"global": "^4.3.2",
"react": "^16.4.2",
Expand Down
13 changes: 7 additions & 6 deletions app/angular/src/server/ts_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ function resolveTsConfig(tsConfigPath) {
}

export default function(configDir) {
const configFile = resolveTsConfig(path.resolve(configDir, 'tsconfig.json'));
const tsLoaderOptions = {
transpileOnly: true,
};
const configFilePath = resolveTsConfig(path.resolve(configDir, 'tsconfig.json'));

if (!configFile) {
return {};
if (configFilePath) {
tsLoaderOptions.configFile = configFilePath;
}

return {
configFile,
};
return tsLoaderOptions;
}
13 changes: 8 additions & 5 deletions app/angular/src/server/ts_config.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import loadTsConfig from './ts_config';
import getTsLoaderOptions from './ts_config';

// eslint-disable-next-line global-require
jest.mock('fs', () => require('../../../../__mocks__/fs'));
Expand All @@ -15,18 +15,21 @@ describe('ts_config', () => {
it('should return the config with the path to the tsconfig.json', () => {
setupFiles({ 'tsconfig.json': '{}' });

const config = loadTsConfig('.foo');
const config = getTsLoaderOptions('.foo');

expect(config).toEqual({
transpileOnly: true,
configFile: 'tsconfig.json',
});
});

it('should return empty object when there is no tsconfig.json', () => {
it('should return object with transpileOnly: true when there is no tsconfig.json', () => {
setupFiles({});

const config = loadTsConfig('.foo');
const config = getTsLoaderOptions('.foo');

expect(config).toEqual({});
expect(config).toEqual({
transpileOnly: true,
});
});
});
92 changes: 51 additions & 41 deletions app/angular/src/server/wrapInitialConfig.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
import path from 'path';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please solve merge conflicts here, it moved to framework-preset-angular

import { ContextReplacementPlugin } from 'webpack';
import loadTsConfig from './ts_config';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import getTsLoaderOptions from './ts_config';

export default (config, configDir) => ({
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.tsx?$/,
use: [
{
loader: require.resolve('ts-loader'),
options: loadTsConfig(configDir),
},
require.resolve('angular2-template-loader'),
],
},
{
test: /[/\\]@angular[/\\]core[/\\].+\.js$/,
parser: { system: true },
},
{
test: /\.html$/,
loader: 'raw-loader',
exclude: /\.async\.html$/,
},
{
test: /\.scss$/,
use: [require.resolve('raw-loader'), require.resolve('sass-loader')],
},
export default (config, configDir) => {
const tsLoaderOptions = getTsLoaderOptions(configDir);
return {
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.tsx?$/,
use: [
{
loader: require.resolve('ts-loader'),
options: tsLoaderOptions,
},
require.resolve('angular2-template-loader'),
],
},
{
test: /[/\\]@angular[/\\]core[/\\].+\.js$/,
parser: { system: true },
},
{
test: /\.html$/,
loader: 'raw-loader',
exclude: /\.async\.html$/,
},
{
test: /\.scss$/,
use: [require.resolve('raw-loader'), require.resolve('sass-loader')],
},
],
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.ts', '.tsx'],
},
plugins: [
...config.plugins,
// See https://github.com/angular/angular/issues/11580#issuecomment-401127742
new ContextReplacementPlugin(
/@angular(\\|\/)core(\\|\/)fesm5/,
path.resolve(__dirname, '..')
),
new ForkTsCheckerWebpackPlugin({
tsconfig: tsLoaderOptions.configFile,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen if there is not a configFile ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, if tslint is always located in root, we can also add it here (just check if it exists).

}),
],
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.ts', '.tsx'],
},
plugins: [
...config.plugins,
// See https://github.com/angular/angular/issues/11580#issuecomment-401127742
new ContextReplacementPlugin(/@angular(\\|\/)core(\\|\/)fesm5/, path.resolve(__dirname, '..')),
],
});
};
};
29 changes: 28 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4472,7 +4472,7 @@ chokidar@^1.4.2, chokidar@^1.4.3, chokidar@^1.5.1:
optionalDependencies:
fsevents "^1.0.0"

chokidar@^2.0.0, chokidar@^2.0.2, chokidar@^2.0.3:
chokidar@^2.0.0, chokidar@^2.0.2, chokidar@^2.0.3, chokidar@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.0.4.tgz#356ff4e2b0e8e43e322d18a372460bbcf3accd26"
dependencies:
Expand Down Expand Up @@ -7567,6 +7567,21 @@ forever-agent@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"

fork-ts-checker-webpack-plugin@^0.4.9:
version "0.4.9"
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-0.4.9.tgz#78607899d4411fdc6faeca5b4db7654c9d8d28a2"
dependencies:
babel-code-frame "^6.22.0"
chalk "^2.4.1"
chokidar "^2.0.4"
lodash.endswith "^4.2.1"
lodash.isfunction "^3.0.8"
lodash.isstring "^4.0.1"
lodash.startswith "^4.2.1"
minimatch "^3.0.4"
resolve "^1.5.0"
tapable "^1.0.0"

form-data@~2.1.1:
version "2.1.4"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.4.tgz#33c183acf193276ecaa98143a69e94bfee1750d1"
Expand Down Expand Up @@ -11060,6 +11075,10 @@ lodash.defaults@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"

lodash.endswith@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/lodash.endswith/-/lodash.endswith-4.2.1.tgz#fed59ac1738ed3e236edd7064ec456448b37bc09"

lodash.escape@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.escape/-/lodash.escape-4.0.1.tgz#c9044690c21e04294beaa517712fded1fa88de98"
Expand Down Expand Up @@ -11107,6 +11126,10 @@ lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"

lodash.isfunction@^3.0.8:
version "3.0.9"
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051"

lodash.isinteger@^4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343"
Expand Down Expand Up @@ -11191,6 +11214,10 @@ lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"

lodash.startswith@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/lodash.startswith/-/lodash.startswith-4.2.1.tgz#c598c4adce188a27e53145731cdc6c0e7177600c"

lodash.tail@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.tail/-/lodash.tail-4.1.1.tgz#d2333a36d9e7717c8ad2f7cacafec7c32b444664"
Expand Down