@storybook/builder-webpack5 6.5.9 → 7.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/cjs/index.js +51 -4
  2. package/dist/cjs/presets/custom-webpack-preset.js +4 -4
  3. package/dist/cjs/preview/babel-loader-preview.js +3 -14
  4. package/dist/cjs/preview/base-webpack.config.js +4 -4
  5. package/dist/cjs/preview/iframe-webpack.config.js +35 -28
  6. package/dist/cjs/preview/virtualModuleStory.template.js +2 -2
  7. package/dist/cjs/types.js +5 -0
  8. package/dist/esm/index.js +26 -4
  9. package/dist/esm/presets/custom-webpack-preset.js +2 -2
  10. package/dist/esm/preview/babel-loader-preview.js +2 -11
  11. package/dist/esm/preview/base-webpack.config.js +4 -4
  12. package/dist/esm/preview/iframe-webpack.config.js +39 -28
  13. package/dist/esm/preview/virtualModuleStory.template.js +1 -1
  14. package/dist/esm/types.js +1 -0
  15. package/dist/{ts3.9 → types}/index.d.ts +6 -2
  16. package/dist/{ts3.9 → types}/presets/custom-webpack-preset.d.ts +1 -1
  17. package/dist/{ts3.9 → types}/presets/preview-preset.d.ts +0 -0
  18. package/dist/types/preview/babel-loader-preview.d.ts +10 -0
  19. package/dist/{ts3.9 → types}/preview/base-webpack.config.d.ts +0 -0
  20. package/dist/types/preview/iframe-webpack.config.d.ts +7 -0
  21. package/dist/types/types.d.ts +40 -0
  22. package/package.json +34 -39
  23. package/templates/virtualModuleModernEntry.js.handlebars +2 -2
  24. package/dist/cjs/preview/useBaseTsSupport.js +0 -17
  25. package/dist/esm/preview/useBaseTsSupport.js +0 -8
  26. package/dist/modern/index.js +0 -254
  27. package/dist/modern/presets/custom-webpack-preset.js +0 -49
  28. package/dist/modern/presets/preview-preset.js +0 -31
  29. package/dist/modern/preview/babel-loader-preview.js +0 -21
  30. package/dist/modern/preview/base-webpack.config.js +0 -84
  31. package/dist/modern/preview/iframe-webpack.config.js +0 -207
  32. package/dist/modern/preview/useBaseTsSupport.js +0 -8
  33. package/dist/modern/preview/virtualModuleEntry.template.js +0 -83
  34. package/dist/modern/preview/virtualModuleStory.template.js +0 -3
  35. package/dist/ts3.4/index.d.ts +0 -14
  36. package/dist/ts3.4/presets/custom-webpack-preset.d.ts +0 -6
  37. package/dist/ts3.4/presets/preview-preset.d.ts +0 -3
  38. package/dist/ts3.4/preview/babel-loader-preview.d.ts +0 -14
  39. package/dist/ts3.4/preview/base-webpack.config.d.ts +0 -3
  40. package/dist/ts3.4/preview/iframe-webpack.config.d.ts +0 -4
  41. package/dist/ts3.4/preview/useBaseTsSupport.d.ts +0 -5
  42. package/dist/ts3.9/preview/babel-loader-preview.d.ts +0 -14
  43. package/dist/ts3.9/preview/iframe-webpack.config.d.ts +0 -4
  44. package/dist/ts3.9/preview/useBaseTsSupport.d.ts +0 -5
@@ -1,207 +0,0 @@
1
- import "core-js/modules/es.promise.js";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
- import path from 'path';
10
- import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';
11
- import HtmlWebpackPlugin from 'html-webpack-plugin';
12
- import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
13
- import TerserWebpackPlugin from 'terser-webpack-plugin';
14
- import VirtualModulePlugin from 'webpack-virtual-modules';
15
- import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
16
- import themingPaths from '@storybook/theming/paths';
17
- import { toRequireContextString, es6Transpiler, stringifyProcessEnvs, handlebars, interpolate, toImportFn, normalizeStories, readTemplate, loadPreviewOrConfigFile } from '@storybook/core-common';
18
- import { createBabelLoader } from './babel-loader-preview';
19
- import { useBaseTsSupport } from './useBaseTsSupport';
20
- var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'components', 'core-events', 'router', 'theming', 'semver', 'client-api', 'client-logger'].reduce(function (acc, sbPackage) {
21
- return _objectSpread(_objectSpread({}, acc), {}, {
22
- [`@storybook/${sbPackage}`]: path.dirname(require.resolve(`@storybook/${sbPackage}/package.json`))
23
- });
24
- }, {});
25
- export default (async function (options) {
26
- var babelOptions = options.babelOptions,
27
- _options$outputDir = options.outputDir,
28
- outputDir = _options$outputDir === void 0 ? path.join('.', 'public') : _options$outputDir,
29
- quiet = options.quiet,
30
- packageJson = options.packageJson,
31
- configType = options.configType,
32
- framework = options.framework,
33
- frameworkPath = options.frameworkPath,
34
- presets = options.presets,
35
- previewUrl = options.previewUrl,
36
- typescriptOptions = options.typescriptOptions,
37
- modern = options.modern,
38
- features = options.features,
39
- serverChannelUrl = options.serverChannelUrl;
40
- var envs = await presets.apply('env');
41
- var logLevel = await presets.apply('logLevel', undefined);
42
- var frameworkOptions = await presets.apply(`${framework}Options`, {});
43
- var headHtmlSnippet = await presets.apply('previewHead');
44
- var bodyHtmlSnippet = await presets.apply('previewBody');
45
- var template = await presets.apply('previewMainTemplate');
46
- var coreOptions = await presets.apply('core');
47
- var babelLoader = createBabelLoader(babelOptions, framework);
48
- var isProd = configType === 'PRODUCTION';
49
- var configs = [...(await presets.apply('config', [], options)), loadPreviewOrConfigFile(options)].filter(Boolean);
50
- var entries = await presets.apply('entries', [], options);
51
- var workingDir = process.cwd();
52
- var stories = normalizeStories(await presets.apply('stories', [], options), {
53
- configDir: options.configDir,
54
- workingDir: workingDir
55
- });
56
- var virtualModuleMapping = {};
57
-
58
- if (features !== null && features !== void 0 && features.storyStoreV7) {
59
- var storiesFilename = 'storybook-stories.js';
60
- var storiesPath = path.resolve(path.join(workingDir, storiesFilename));
61
- virtualModuleMapping[storiesPath] = toImportFn(stories);
62
- var configEntryPath = path.resolve(path.join(workingDir, 'storybook-config-entry.js'));
63
- virtualModuleMapping[configEntryPath] = handlebars(await readTemplate(require.resolve('@storybook/builder-webpack5/templates/virtualModuleModernEntry.js.handlebars')), {
64
- storiesFilename: storiesFilename,
65
- configs: configs
66
- } // We need to double escape `\` for webpack. We may have some in windows paths
67
- ).replace(/\\/g, '\\\\');
68
- entries.push(configEntryPath);
69
- } else {
70
- var frameworkInitEntry = path.resolve(path.join(workingDir, 'storybook-init-framework-entry.js'));
71
- var frameworkImportPath = frameworkPath || `@storybook/${framework}`;
72
- virtualModuleMapping[frameworkInitEntry] = `import '${frameworkImportPath}';`;
73
- entries.push(frameworkInitEntry);
74
- var entryTemplate = await readTemplate(path.join(__dirname, 'virtualModuleEntry.template.js'));
75
- configs.forEach(function (configFilename) {
76
- var clientApi = storybookPaths['@storybook/client-api'];
77
- var clientLogger = storybookPaths['@storybook/client-logger']; // NOTE: although this file is also from the `dist/cjs` directory, it is actually a ESM
78
- // file, see https://github.com/storybookjs/storybook/pull/16727#issuecomment-986485173
79
-
80
- virtualModuleMapping[`${configFilename}-generated-config-entry.js`] = interpolate(entryTemplate, {
81
- configFilename: configFilename,
82
- clientApi: clientApi,
83
- clientLogger: clientLogger
84
- });
85
- entries.push(`${configFilename}-generated-config-entry.js`);
86
- });
87
-
88
- if (stories.length > 0) {
89
- var storyTemplate = await readTemplate(path.join(__dirname, 'virtualModuleStory.template.js')); // NOTE: this file has a `.cjs` extension as it is a CJS file (from `dist/cjs`) and runs
90
- // in the user's webpack mode, which may be strict about the use of require/import.
91
- // See https://github.com/storybookjs/storybook/issues/14877
92
-
93
- var _storiesFilename = path.resolve(path.join(workingDir, `generated-stories-entry.cjs`));
94
-
95
- virtualModuleMapping[_storiesFilename] = interpolate(storyTemplate, {
96
- frameworkImportPath: frameworkImportPath
97
- }) // Make sure we also replace quotes for this one
98
- .replace("'{{stories}}'", stories.map(toRequireContextString).join(','));
99
- entries.push(_storiesFilename);
100
- }
101
- }
102
-
103
- var shouldCheckTs = useBaseTsSupport(framework) && typescriptOptions.check;
104
- var tsCheckOptions = typescriptOptions.checkOptions || {};
105
- return {
106
- name: 'preview',
107
- mode: isProd ? 'production' : 'development',
108
- bail: isProd,
109
- devtool: 'cheap-module-source-map',
110
- entry: entries,
111
- output: {
112
- path: path.resolve(process.cwd(), outputDir),
113
- filename: isProd ? '[name].[contenthash:8].iframe.bundle.js' : '[name].iframe.bundle.js',
114
- publicPath: ''
115
- },
116
- stats: {
117
- preset: 'none',
118
- logging: 'error'
119
- },
120
- watchOptions: {
121
- ignored: /node_modules/
122
- },
123
- ignoreWarnings: [{
124
- message: /export '\S+' was not found in 'global'/
125
- }],
126
- plugins: [Object.keys(virtualModuleMapping).length > 0 ? new VirtualModulePlugin(virtualModuleMapping) : null, new HtmlWebpackPlugin({
127
- filename: `iframe.html`,
128
- // FIXME: `none` isn't a known option
129
- chunksSortMode: 'none',
130
- alwaysWriteToDisk: true,
131
- inject: false,
132
- template: template,
133
- templateParameters: {
134
- version: packageJson.version,
135
- globals: {
136
- CONFIG_TYPE: configType,
137
- LOGLEVEL: logLevel,
138
- FRAMEWORK_OPTIONS: frameworkOptions,
139
- CHANNEL_OPTIONS: coreOptions === null || coreOptions === void 0 ? void 0 : coreOptions.channelOptions,
140
- FEATURES: features,
141
- PREVIEW_URL: previewUrl,
142
- STORIES: stories.map(function (specifier) {
143
- return _objectSpread(_objectSpread({}, specifier), {}, {
144
- importPathMatcher: specifier.importPathMatcher.source
145
- });
146
- }),
147
- SERVER_CHANNEL_URL: serverChannelUrl
148
- },
149
- headHtmlSnippet: headHtmlSnippet,
150
- bodyHtmlSnippet: bodyHtmlSnippet
151
- },
152
- minify: {
153
- collapseWhitespace: true,
154
- removeComments: true,
155
- removeRedundantAttributes: true,
156
- removeScriptTypeAttributes: false,
157
- removeStyleLinkTypeAttributes: true,
158
- useShortDoctype: true
159
- }
160
- }), new DefinePlugin(_objectSpread(_objectSpread({}, stringifyProcessEnvs(envs)), {}, {
161
- NODE_ENV: JSON.stringify(process.env.NODE_ENV)
162
- })), new ProvidePlugin({
163
- process: require.resolve('process/browser.js')
164
- }), isProd ? null : new HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), quiet ? null : new ProgressPlugin({}), shouldCheckTs ? new ForkTsCheckerWebpackPlugin(tsCheckOptions) : null].filter(Boolean),
165
- module: {
166
- rules: [babelLoader, es6Transpiler(), {
167
- test: /\.md$/,
168
- type: 'asset/source'
169
- }]
170
- },
171
- resolve: {
172
- extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
173
- modules: ['node_modules'].concat(envs.NODE_PATH || []),
174
- mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
175
- alias: _objectSpread(_objectSpread(_objectSpread({}, features !== null && features !== void 0 && features.emotionAlias ? themingPaths : {}), storybookPaths), {}, {
176
- react: path.dirname(require.resolve('react/package.json')),
177
- 'react-dom': path.dirname(require.resolve('react-dom/package.json'))
178
- }),
179
- fallback: {
180
- path: require.resolve('path-browserify'),
181
- assert: require.resolve('browser-assert')
182
- }
183
- },
184
- optimization: {
185
- splitChunks: {
186
- chunks: 'all'
187
- },
188
- runtimeChunk: true,
189
- sideEffects: true,
190
- usedExports: isProd,
191
- moduleIds: 'named',
192
- minimizer: isProd ? [new TerserWebpackPlugin({
193
- parallel: true,
194
- terserOptions: {
195
- sourceMap: true,
196
- mangle: false,
197
- keep_fnames: true
198
- } // It looks like the types from `@types/terser-webpack-plugin` are not matching the latest version of
199
- // Webpack yet
200
-
201
- })] : []
202
- },
203
- performance: {
204
- hints: isProd ? 'warning' : false
205
- }
206
- };
207
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * Returns true if the framework can use the base TS config.
3
- * @param {string} framework
4
- */
5
- export var useBaseTsSupport = function (framework) {
6
- // These packages both have their own TS implementation.
7
- return !['vue', 'angular'].includes(framework);
8
- };
@@ -1,83 +0,0 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- /* eslint-disable import/no-unresolved */
8
- import { addDecorator, addParameters, addLoader, addArgs, addArgTypes, addArgsEnhancer, addArgTypesEnhancer, setGlobalRender } from '{{clientApi}}';
9
- import * as config from '{{configFilename}}';
10
- Object.keys(config).forEach(function (key) {
11
- var value = config[key];
12
-
13
- switch (key) {
14
- case 'args':
15
- {
16
- return addArgs(value);
17
- }
18
-
19
- case 'argTypes':
20
- {
21
- return addArgTypes(value);
22
- }
23
-
24
- case 'decorators':
25
- {
26
- return value.forEach(function (decorator) {
27
- return addDecorator(decorator, false);
28
- });
29
- }
30
-
31
- case 'loaders':
32
- {
33
- return value.forEach(function (loader) {
34
- return addLoader(loader, false);
35
- });
36
- }
37
-
38
- case 'parameters':
39
- {
40
- return addParameters(_objectSpread({}, value), false);
41
- }
42
-
43
- case 'argTypesEnhancers':
44
- {
45
- return value.forEach(function (enhancer) {
46
- return addArgTypesEnhancer(enhancer);
47
- });
48
- }
49
-
50
- case 'argsEnhancers':
51
- {
52
- return value.forEach(function (enhancer) {
53
- return addArgsEnhancer(enhancer);
54
- });
55
- }
56
-
57
- case 'render':
58
- {
59
- return setGlobalRender(value);
60
- }
61
-
62
- case 'globals':
63
- case 'globalTypes':
64
- {
65
- var v = {};
66
- v[key] = value;
67
- return addParameters(v, false);
68
- }
69
-
70
- case '__namedExportsOrder':
71
- case 'decorateStory':
72
- case 'renderToDOM':
73
- {
74
- return null; // This key is not handled directly in v6 mode.
75
- }
76
-
77
- default:
78
- {
79
- // eslint-disable-next-line prefer-template
80
- return console.log(key + ' was not supported :( !');
81
- }
82
- }
83
- });
@@ -1,3 +0,0 @@
1
- /* eslint-disable import/no-unresolved */
2
- import { configure } from '{{frameworkImportPath}}';
3
- configure(['{{stories}}'], module, false);
@@ -1,14 +0,0 @@
1
- import webpack, { Stats, Configuration } from 'webpack';
2
- import { Builder, Options } from '@storybook/core-common';
3
- declare type WebpackBuilder = Builder<Configuration, Stats>;
4
- declare type BuilderStartOptions = Partial<Parameters<WebpackBuilder['start']>['0']>;
5
- export declare const executor: {
6
- get: (options: Options) => Promise<typeof webpack>;
7
- };
8
- export declare const getConfig: WebpackBuilder['getConfig'];
9
- export declare const bail: WebpackBuilder['bail'];
10
- export declare const start: (options: BuilderStartOptions) => Promise<unknown>;
11
- export declare const build: (options: BuilderStartOptions) => Promise<void | webpack.Stats>;
12
- export declare const corePresets: string[];
13
- export declare const overridePresets: string[];
14
- export {};
@@ -1,6 +0,0 @@
1
- import * as webpackReal from 'webpack';
2
- import { Options } from '@storybook/core-common';
3
- import { Configuration } from 'webpack';
4
- export declare function webpack(config: Configuration, options: Options): Promise<any>;
5
- export declare const webpackInstance: () => Promise<typeof webpackReal>;
6
- export declare const webpackVersion: () => Promise<string>;
@@ -1,3 +0,0 @@
1
- export declare const webpack: (_: unknown, options: any) => Promise<import("webpack").Configuration>;
2
- export declare const entries: (_: unknown, options: any) => Promise<string[]>;
3
- export declare const babel: (config: any, options: any) => Promise<any>;
@@ -1,14 +0,0 @@
1
- /**
2
- * Returns true if the framework can use the base TS config.
3
- * @param {string} framework
4
- */
5
- export declare const useBaseTsSupport: (framework: string) => boolean;
6
- export declare const createBabelLoader: (options: any, framework: string) => {
7
- test: RegExp;
8
- use: {
9
- loader: string;
10
- options: any;
11
- }[];
12
- include: string[];
13
- exclude: RegExp;
14
- };
@@ -1,3 +0,0 @@
1
- import { Options } from '@storybook/core-common';
2
- import { Configuration } from 'webpack';
3
- export declare function createDefaultWebpackConfig(storybookBaseConfig: Configuration, options: Options): Promise<Configuration>;
@@ -1,4 +0,0 @@
1
- import { Configuration } from 'webpack';
2
- import { Options } from '@storybook/core-common';
3
- declare const _default: (options: Options & Record<string, any>) => Promise<Configuration>;
4
- export default _default;
@@ -1,5 +0,0 @@
1
- /**
2
- * Returns true if the framework can use the base TS config.
3
- * @param {string} framework
4
- */
5
- export declare const useBaseTsSupport: (framework: string) => boolean;
@@ -1,14 +0,0 @@
1
- /**
2
- * Returns true if the framework can use the base TS config.
3
- * @param {string} framework
4
- */
5
- export declare const useBaseTsSupport: (framework: string) => boolean;
6
- export declare const createBabelLoader: (options: any, framework: string) => {
7
- test: RegExp;
8
- use: {
9
- loader: string;
10
- options: any;
11
- }[];
12
- include: string[];
13
- exclude: RegExp;
14
- };
@@ -1,4 +0,0 @@
1
- import type { Configuration } from 'webpack';
2
- import type { Options } from '@storybook/core-common';
3
- declare const _default: (options: Options & Record<string, any>) => Promise<Configuration>;
4
- export default _default;
@@ -1,5 +0,0 @@
1
- /**
2
- * Returns true if the framework can use the base TS config.
3
- * @param {string} framework
4
- */
5
- export declare const useBaseTsSupport: (framework: string) => boolean;