UNPKG

3.84 kBJavaScriptView Raw
1var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10// Private angular devkit stuff
11const { generateI18nBrowserWebpackConfigFromContext, } = require('@angular-devkit/build-angular/src/utils/webpack-browser-config');
12const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig, } = require('@angular-devkit/build-angular/src/webpack/configs');
13const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
14const { filterOutStylingRules } = require('./utils/filter-out-styling-rules');
15const { default: StorybookNormalizeAngularEntryPlugin, } = require('./plugins/storybook-normalize-angular-entry-plugin');
16/**
17 * Extract webpack config from angular-cli 13.x.x
18 * ⚠️ This file is in JavaScript to not use TypeScript. Because current storybook TypeScript version is not compatible with Angular CLI.
19 * FIXME: Try another way with TypeScript on future storybook version (7 maybe 🤞)
20 *
21 * @param {*} baseConfig Previous webpack config from storybook
22 * @param {*} options { builderOptions, builderContext }
23 */
24exports.getWebpackConfig = (baseConfig, { builderOptions, builderContext }) => __awaiter(void 0, void 0, void 0, function* () {
25 var _a, _b, _c;
26 /**
27 * Get angular-cli Webpack config
28 */
29 const { config: cliConfig } = yield generateI18nBrowserWebpackConfigFromContext(Object.assign(Object.assign({
30 // Default options
31 index: 'noop-index', main: 'noop-main', outputPath: 'noop-out' }, builderOptions), {
32 // Fixed options
33 optimization: false, namedChunks: false, progress: false, buildOptimizer: false, aot: false }), builderContext, (wco) => [
34 getCommonConfig(wco),
35 getStylesConfig(wco),
36 getTypeScriptConfig ? getTypeScriptConfig(wco) : getDevServerConfig(wco),
37 ]);
38 /**
39 * Merge baseConfig Webpack with angular-cli Webpack
40 */
41 const entry = [
42 ...baseConfig.entry,
43 ...((_a = cliConfig.entry.styles) !== null && _a !== void 0 ? _a : []),
44 ...((_b = cliConfig.entry.polyfills) !== null && _b !== void 0 ? _b : []),
45 ];
46 // Don't use storybooks styling rules because we have to use rules created by @angular-devkit/build-angular
47 // because @angular-devkit/build-angular created rules have include/exclude for global style files.
48 const rulesExcludingStyles = filterOutStylingRules(baseConfig);
49 const module = Object.assign(Object.assign({}, baseConfig.module), { rules: [...cliConfig.module.rules, ...rulesExcludingStyles] });
50 const plugins = [
51 ...((_c = cliConfig.plugins) !== null && _c !== void 0 ? _c : []),
52 ...baseConfig.plugins,
53 new StorybookNormalizeAngularEntryPlugin(),
54 ];
55 const resolve = Object.assign(Object.assign({}, baseConfig.resolve), { modules: Array.from(new Set([...baseConfig.resolve.modules, ...cliConfig.resolve.modules])), plugins: [
56 new TsconfigPathsPlugin({
57 configFile: builderOptions.tsConfig,
58 mainFields: ['browser', 'module', 'main'],
59 }),
60 ] });
61 return Object.assign(Object.assign({}, baseConfig), { entry,
62 module,
63 plugins,
64 resolve, resolveLoader: cliConfig.resolveLoader });
65});