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: Fix angular 13.1 JIT error and HMR reload #17131

Merged
merged 3 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 12 additions & 3 deletions app/angular/src/server/framework-preset-angular-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logger } from '@storybook/node-logger';
import { targetFromTargetString, BuilderContext, Target } from '@angular-devkit/architect';
import { sync as findUpSync } from 'find-up';
import semver from '@storybook/semver';
import dedent from 'ts-dedent';

import { logging, JsonObject } from '@angular-devkit/core';
import { moduleIsAvailable } from './utils/module-is-available';
Expand Down Expand Up @@ -44,7 +45,11 @@ export async function webpackFinal(baseConfig: webpack.Configuration, options: P
const legacyDefaultOptions = await getLegacyDefaultBuildOptions(_options);

return getWebpackConfig13_x_x(_baseConfig, {
builderOptions: { ...builderOptions, ...legacyDefaultOptions },
builderOptions: {
watch: options.configType === 'DEVELOPMENT',
...builderOptions,
...legacyDefaultOptions,
},
builderContext,
});
},
Expand Down Expand Up @@ -142,8 +147,12 @@ async function getLegacyDefaultBuildOptions(options: PresetOptions) {
return {};
}

// TODO ~ legacy way to get default options
// TODO ~ Add deprecation warning and ex for builder use ? `);
logger.warn(dedent`Your Storybook startup uses a solution that will not be supported in version 7.0.
You must use angular builder to have an explicit configuration on the project used in angular.json
Read more at:
- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#sb-angular-builder)
- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#angular13)
`);
const dirToSearch = process.cwd();

// Read angular workspace
Expand Down
23 changes: 20 additions & 3 deletions app/angular/src/server/framework-preset-angular.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import path from 'path';
import semver from '@storybook/semver';
import { ContextReplacementPlugin, Configuration } from 'webpack';
import autoprefixer from 'autoprefixer';
import getTsLoaderOptions from './ts_config';
import createForkTsCheckerInstance from './create-fork-ts-checker-plugin';

export function webpack(
export async function webpack(
config: Configuration,
{ configDir }: { configDir: string }
): Configuration {
{ configDir, angularBuilderContext }: { configDir: string; angularBuilderContext: any }
): Promise<Configuration> {
try {
// Disable all this webpack stuff if we use angular-cli >= 12
// Angular cli is in charge of doing all the necessary for angular. If there is any additional configuration to add, it must be done in the preset angular-cli versioned.
const angularCliVersion = await import('@angular/cli').then((m) =>
semver.coerce(m.VERSION.full)
);
if (
(semver.satisfies(angularCliVersion, '12.2.x') && angularBuilderContext) ||
semver.satisfies(angularCliVersion, '>=13.0.0')
) {
return config;
}
} catch (error) {
// do nothing, continue
}

const tsLoaderOptions = getTsLoaderOptions(configDir);
return {
...config,
Expand Down