@storybook/builder-webpack5 6.4.0-alpha.4 → 6.4.0-alpha.40

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.
package/dist/cjs/index.js CHANGED
@@ -38,13 +38,9 @@ var getConfig = async function (options) {
38
38
  var babelOptions = await presets.apply('babel', {}, _objectSpread(_objectSpread({}, options), {}, {
39
39
  typescriptOptions: typescriptOptions
40
40
  }));
41
- var entries = await presets.apply('entries', [], options);
42
- var stories = await presets.apply('stories', [], options);
43
41
  var frameworkOptions = await presets.apply(`${options.framework}Options`, {}, options);
44
42
  return presets.apply('webpack', {}, _objectSpread(_objectSpread({}, options), {}, {
45
43
  babelOptions: babelOptions,
46
- entries: entries,
47
- stories: stories,
48
44
  typescriptOptions: typescriptOptions,
49
45
  [`${options.framework}Options`]: frameworkOptions
50
46
  }));
@@ -168,7 +164,8 @@ var build = async function ({
168
164
 
169
165
  var config = await getConfig(options);
170
166
  return new Promise(function (succeed, fail) {
171
- webpackInstance(config).run(function (error, stats) {
167
+ var compiler = webpackInstance(config);
168
+ compiler.run(function (error, stats) {
172
169
  if (error || !stats || stats.hasErrors()) {
173
170
  _nodeLogger.logger.error('=> Failed to build the preview');
174
171
 
@@ -177,7 +174,10 @@ var build = async function ({
177
174
  if (error) {
178
175
  _nodeLogger.logger.error(error.message);
179
176
 
180
- return fail(error);
177
+ compiler.close(function () {
178
+ return fail(error);
179
+ });
180
+ return;
181
181
  }
182
182
 
183
183
  if (stats && (stats.hasErrors() || stats.hasWarnings())) {
@@ -196,7 +196,10 @@ var build = async function ({
196
196
  warnings.forEach(function (e) {
197
197
  return _nodeLogger.logger.error(e.message);
198
198
  });
199
- return fail(stats);
199
+ compiler.close(function () {
200
+ return fail(stats);
201
+ });
202
+ return;
200
203
  }
201
204
  }
202
205
 
@@ -211,9 +214,17 @@ var build = async function ({
211
214
  }).warnings.forEach(function (e) {
212
215
  return _nodeLogger.logger.warn(e.message);
213
216
  });
214
- }
217
+ } // https://webpack.js.org/api/node/#run
218
+ // #15227
219
+
215
220
 
216
- return succeed(stats);
221
+ compiler.close(function (closeErr) {
222
+ if (closeErr) {
223
+ return fail(closeErr);
224
+ }
225
+
226
+ return succeed(stats);
227
+ });
217
228
  });
218
229
  });
219
230
  };
@@ -9,8 +9,6 @@ require("core-js/modules/es.promise.js");
9
9
 
10
10
  var _iframeWebpack = _interopRequireDefault(require("../preview/iframe-webpack.config"));
11
11
 
12
- var _entries = require("../preview/entries");
13
-
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
16
14
  var webpack = async function (_, options) {
@@ -21,7 +19,7 @@ exports.webpack = webpack;
21
19
 
22
20
  var entries = async function (_, options) {
23
21
  var result = [];
24
- result = result.concat(await (0, _entries.createPreviewEntry)(options));
22
+ result = result.concat(await options.presets.apply('previewEntries', [], options));
25
23
 
26
24
  if (options.configType === 'DEVELOPMENT') {
27
25
  // Suppress informational messages when --quiet is specified. webpack-hot-middleware's quiet
@@ -55,7 +55,7 @@ async function createDefaultWebpackConfig(storybookBaseConfig, options) {
55
55
  test: /\.(svg|ico|jpg|jpeg|png|apng|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,
56
56
  type: 'asset/resource',
57
57
  generator: {
58
- filename: isProd ? 'static/media/[name].[contenthash:8].[ext]' : 'static/media/[path][name].[ext]'
58
+ filename: isProd ? 'static/media/[name].[contenthash:8][ext]' : 'static/media/[path][name][ext]'
59
59
  }
60
60
  }, {
61
61
  test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
@@ -66,7 +66,7 @@ async function createDefaultWebpackConfig(storybookBaseConfig, options) {
66
66
  }
67
67
  },
68
68
  generator: {
69
- filename: isProd ? 'static/media/[name].[contenthash:8].[ext]' : 'static/media/[path][name].[ext]'
69
+ filename: isProd ? 'static/media/[name].[contenthash:8][ext]' : 'static/media/[path][name][ext]'
70
70
  }
71
71
  }]
72
72
  }),
@@ -9,8 +9,6 @@ require("core-js/modules/es.promise.js");
9
9
 
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
 
12
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
-
14
12
  var _webpack = require("webpack");
15
13
 
16
14
  var _dotenvWebpack = _interopRequireDefault(require("dotenv-webpack"));
@@ -49,22 +47,20 @@ var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'compo
49
47
  });
50
48
  }, {});
51
49
 
52
- var _default = async function _default({
53
- configDir: configDir,
54
- babelOptions: babelOptions,
55
- entries: entries,
56
- stories: stories,
57
- outputDir = _path.default.join('.', 'public'),
58
- quiet: quiet,
59
- packageJson: packageJson,
60
- configType: configType,
61
- framework: framework,
62
- frameworkPath: frameworkPath,
63
- presets: presets,
64
- typescriptOptions: typescriptOptions,
65
- modern: modern,
66
- features: features
67
- }) {
50
+ var _default = async function _default(options) {
51
+ var configDir = options.configDir,
52
+ babelOptions = options.babelOptions,
53
+ _options$outputDir = options.outputDir,
54
+ outputDir = _options$outputDir === void 0 ? _path.default.join('.', 'public') : _options$outputDir,
55
+ quiet = options.quiet,
56
+ packageJson = options.packageJson,
57
+ configType = options.configType,
58
+ framework = options.framework,
59
+ frameworkPath = options.frameworkPath,
60
+ presets = options.presets,
61
+ typescriptOptions = options.typescriptOptions,
62
+ modern = options.modern,
63
+ features = options.features;
68
64
  var envs = await presets.apply('env');
69
65
  var logLevel = await presets.apply('logLevel', undefined);
70
66
  var frameworkOptions = await presets.apply(`${framework}Options`, {});
@@ -72,46 +68,60 @@ var _default = async function _default({
72
68
  var bodyHtmlSnippet = await presets.apply('previewBody');
73
69
  var template = await presets.apply('previewMainTemplate');
74
70
  var babelLoader = (0, _babelLoaderPreview.createBabelLoader)(babelOptions, framework);
75
- var isProd = configType === 'PRODUCTION'; // TODO FIX ME - does this need to be ESM?
76
-
77
- var entryTemplate = await _fsExtra.default.readFile(_path.default.join(__dirname, 'virtualModuleEntry.template.js'), {
78
- encoding: 'utf8'
79
- });
80
- var storyTemplate = await _fsExtra.default.readFile(_path.default.join(__dirname, 'virtualModuleStory.template.js'), {
81
- encoding: 'utf8'
71
+ var isProd = configType === 'PRODUCTION';
72
+ var configs = [...(await presets.apply('config', [], options)), (0, _coreCommon.loadPreviewOrConfigFile)(options)].filter(Boolean);
73
+ var entries = await presets.apply('entries', [], options);
74
+ var stories = (0, _coreCommon.normalizeStories)(await presets.apply('stories', [], options), {
75
+ configDir: options.configDir,
76
+ workingDir: process.cwd()
82
77
  });
78
+ var virtualModuleMapping = {};
83
79
 
84
- var frameworkInitEntry = _path.default.resolve(_path.default.join(configDir, 'storybook-init-framework-entry.js')); // Allows for custom frameworks that are not published under the @storybook namespace
80
+ if (features !== null && features !== void 0 && features.storyStoreV7) {
81
+ var storiesFilename = 'storybook-stories.js';
85
82
 
83
+ var storiesPath = _path.default.resolve(_path.default.join(configDir, storiesFilename));
86
84
 
87
- var frameworkImportPath = frameworkPath || `@storybook/${framework}`;
88
- var virtualModuleMapping = {
89
- // Ensure that the client API is initialized by the framework before any other iframe code
90
- // is loaded. That way our client-apis can assume the existence of the API+store
91
- [frameworkInitEntry]: `import '${frameworkImportPath}';`
92
- };
93
- entries.forEach(function (entryFilename) {
94
- var match = entryFilename.match(/(.*)-generated-(config|other)-entry.js$/);
85
+ virtualModuleMapping[storiesPath] = (0, _coreCommon.toImportFn)(stories);
86
+
87
+ var configEntryPath = _path.default.resolve(_path.default.join(configDir, 'storybook-config-entry.js'));
95
88
 
96
- if (match) {
97
- var configFilename = match[1];
89
+ virtualModuleMapping[configEntryPath] = (0, _coreCommon.handlebars)(await (0, _coreCommon.readTemplate)(_path.default.join(__dirname, 'virtualModuleModernEntry.js.handlebars')), {
90
+ storiesFilename: storiesFilename,
91
+ configs: configs
92
+ });
93
+ entries.push(configEntryPath);
94
+ } else {
95
+ var frameworkInitEntry = _path.default.resolve(_path.default.join(configDir, 'storybook-init-framework-entry.js'));
96
+
97
+ var frameworkImportPath = frameworkPath || `@storybook/${framework}`;
98
+ virtualModuleMapping[frameworkInitEntry] = `import '${frameworkImportPath}';`;
99
+ entries.push(frameworkInitEntry);
100
+ var entryTemplate = await (0, _coreCommon.readTemplate)(_path.default.join(__dirname, 'virtualModuleEntry.template.js'));
101
+ configs.forEach(function (configFilename) {
98
102
  var clientApi = storybookPaths['@storybook/client-api'];
99
103
  var clientLogger = storybookPaths['@storybook/client-logger'];
100
- virtualModuleMapping[entryFilename] = (0, _coreCommon.interpolate)(entryTemplate, {
104
+ virtualModuleMapping[`${configFilename}-generated-config-entry.js`] = (0, _coreCommon.interpolate)(entryTemplate, {
101
105
  configFilename: configFilename,
102
106
  clientApi: clientApi,
103
107
  clientLogger: clientLogger
104
108
  });
105
- }
106
- });
109
+ entries.push(`${configFilename}-generated-config-entry.js`);
110
+ });
107
111
 
108
- if (stories) {
109
- var storiesFilename = _path.default.resolve(_path.default.join(configDir, `generated-stories-entry.js`));
112
+ if (stories.length > 0) {
113
+ var storyTemplate = await (0, _coreCommon.readTemplate)(_path.default.join(__dirname, 'virtualModuleStory.template.js'));
110
114
 
111
- virtualModuleMapping[storiesFilename] = (0, _coreCommon.interpolate)(storyTemplate, {
112
- frameworkImportPath: frameworkImportPath
113
- }) // Make sure we also replace quotes for this one
114
- .replace("'{{stories}}'", stories.map(_coreCommon.toRequireContextString).join(','));
115
+ var _storiesFilename = _path.default.resolve(_path.default.join(configDir, `generated-stories-entry.js`));
116
+
117
+ virtualModuleMapping[_storiesFilename] = (0, _coreCommon.interpolate)(storyTemplate, {
118
+ frameworkImportPath: frameworkImportPath
119
+ }) // Make sure we also replace quotes for this one
120
+ .replace("'{{stories}}'", stories.map(function (s) {
121
+ return s.glob;
122
+ }).map(_coreCommon.toRequireContextString).join(','));
123
+ entries.push(_storiesFilename);
124
+ }
115
125
  }
116
126
 
117
127
  var shouldCheckTs = (0, _useBaseTsSupport.useBaseTsSupport)(framework) && typescriptOptions.check;
@@ -132,7 +142,6 @@ var _default = async function _default({
132
142
  logging: 'error'
133
143
  },
134
144
  watchOptions: {
135
- aggregateTimeout: 10,
136
145
  ignored: /node_modules/
137
146
  },
138
147
  ignoreWarnings: [{
@@ -144,16 +153,17 @@ var _default = async function _default({
144
153
  chunksSortMode: 'none',
145
154
  alwaysWriteToDisk: true,
146
155
  inject: false,
147
- templateParameters: function (compilation, files, options) {
156
+ templateParameters: function (compilation, files, templateOptions) {
148
157
  return {
149
158
  compilation: compilation,
150
159
  files: files,
151
- options: options,
160
+ options: templateOptions,
152
161
  version: packageJson.version,
153
162
  globals: {
154
163
  LOGLEVEL: logLevel,
155
164
  FRAMEWORK_OPTIONS: frameworkOptions,
156
- FEATURES: features
165
+ FEATURES: features,
166
+ STORIES: stories
157
167
  },
158
168
  headHtmlSnippet: headHtmlSnippet,
159
169
  bodyHtmlSnippet: bodyHtmlSnippet
@@ -168,10 +178,9 @@ var _default = async function _default({
168
178
  useShortDoctype: true
169
179
  },
170
180
  template: template
171
- }), new _webpack.DefinePlugin({
172
- 'process.env': (0, _coreCommon.stringifyEnvs)(envs),
181
+ }), new _webpack.DefinePlugin(_objectSpread(_objectSpread({}, (0, _coreCommon.stringifyProcessEnvs)(envs)), {}, {
173
182
  NODE_ENV: JSON.stringify(process.env.NODE_ENV)
174
- }), isProd ? null : new _WatchMissingNodeModulesPlugin.default(_coreCommon.nodeModulesPaths), isProd ? null : new _webpack.HotModuleReplacementPlugin(), new _caseSensitivePathsWebpackPlugin.default(), quiet ? null : new _webpack.ProgressPlugin({}), (0, _coreCommon.hasDotenv)() ? new _dotenvWebpack.default({
183
+ })), isProd ? null : new _WatchMissingNodeModulesPlugin.default(_coreCommon.nodeModulesPaths), isProd ? null : new _webpack.HotModuleReplacementPlugin(), new _caseSensitivePathsWebpackPlugin.default(), quiet ? null : new _webpack.ProgressPlugin({}), (0, _coreCommon.hasDotenv)() ? new _dotenvWebpack.default({
175
184
  silent: true
176
185
  }) : null, shouldCheckTs ? new _forkTsCheckerWebpackPlugin.default(tsCheckOptions) : null].filter(Boolean),
177
186
  module: {
@@ -199,6 +208,7 @@ var _default = async function _default({
199
208
  runtimeChunk: true,
200
209
  sideEffects: true,
201
210
  usedExports: true,
211
+ moduleIds: 'named',
202
212
  minimizer: isProd ? [new _terserWebpackPlugin.default({
203
213
  parallel: true,
204
214
  terserOptions: {
@@ -0,0 +1,44 @@
1
+ import fetch from 'unfetch';
2
+
3
+ import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
4
+ import { ClientApi } from '@storybook/client-api';
5
+ import { addons } from '@storybook/addons';
6
+ import createChannel from '@storybook/channel-postmessage';
7
+
8
+ import { importFn } from './{{storiesFilename}}';
9
+
10
+ const getProjectAnnotations = () =>
11
+ composeConfigs([
12
+ {{#each configs}}
13
+ require('{{this}}'),
14
+ {{/each}}
15
+ ]);
16
+
17
+ const fetchStoryIndex = async () => {
18
+ const result = await fetch('./stories.json');
19
+ return result.json();
20
+ }
21
+
22
+ const channel = createChannel({ page: 'preview' });
23
+ addons.setChannel(channel);
24
+
25
+ const preview = new PreviewWeb({ importFn, fetchStoryIndex });
26
+
27
+ window.__STORYBOOK_PREVIEW__ = preview;
28
+ window.__STORYBOOK_STORY_STORE__ = preview.storyStore;
29
+ window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
30
+ window.__STORYBOOK_CLIENT_API__ = new ClientApi({ storyStore: preview.storyStore });
31
+
32
+ preview.initialize({ getProjectAnnotations });
33
+
34
+ if (module.hot) {
35
+ module.hot.accept('./{{storiesFilename}}', () => {
36
+ // importFn has changed so we need to patch the new one in
37
+ preview.onImportFnChanged({ importFn });
38
+ });
39
+
40
+ module.hot.accept([{{#each configs}}'{{this}}',{{/each}}], () => {
41
+ // getProjectAnnotations has changed so we need to patch the new one in
42
+ preview.onGetProjectAnnotationsChanged({ getProjectAnnotations });
43
+ });
44
+ }
package/dist/esm/index.js CHANGED
@@ -18,13 +18,9 @@ export var getConfig = async function (options) {
18
18
  var babelOptions = await presets.apply('babel', {}, _objectSpread(_objectSpread({}, options), {}, {
19
19
  typescriptOptions: typescriptOptions
20
20
  }));
21
- var entries = await presets.apply('entries', [], options);
22
- var stories = await presets.apply('stories', [], options);
23
21
  var frameworkOptions = await presets.apply(`${options.framework}Options`, {}, options);
24
22
  return presets.apply('webpack', {}, _objectSpread(_objectSpread({}, options), {}, {
25
23
  babelOptions: babelOptions,
26
- entries: entries,
27
- stories: stories,
28
24
  typescriptOptions: typescriptOptions,
29
25
  [`${options.framework}Options`]: frameworkOptions
30
26
  }));
@@ -133,14 +129,18 @@ export var build = async function ({
133
129
  logger.info('=> Compiling preview..');
134
130
  var config = await getConfig(options);
135
131
  return new Promise(function (succeed, fail) {
136
- webpackInstance(config).run(function (error, stats) {
132
+ var compiler = webpackInstance(config);
133
+ compiler.run(function (error, stats) {
137
134
  if (error || !stats || stats.hasErrors()) {
138
135
  logger.error('=> Failed to build the preview');
139
136
  process.exitCode = 1;
140
137
 
141
138
  if (error) {
142
139
  logger.error(error.message);
143
- return fail(error);
140
+ compiler.close(function () {
141
+ return fail(error);
142
+ });
143
+ return;
144
144
  }
145
145
 
146
146
  if (stats && (stats.hasErrors() || stats.hasWarnings())) {
@@ -159,7 +159,10 @@ export var build = async function ({
159
159
  warnings.forEach(function (e) {
160
160
  return logger.error(e.message);
161
161
  });
162
- return fail(stats);
162
+ compiler.close(function () {
163
+ return fail(stats);
164
+ });
165
+ return;
163
166
  }
164
167
  }
165
168
 
@@ -174,9 +177,17 @@ export var build = async function ({
174
177
  }).warnings.forEach(function (e) {
175
178
  return logger.warn(e.message);
176
179
  });
177
- }
180
+ } // https://webpack.js.org/api/node/#run
181
+ // #15227
182
+
178
183
 
179
- return succeed(stats);
184
+ compiler.close(function (closeErr) {
185
+ if (closeErr) {
186
+ return fail(closeErr);
187
+ }
188
+
189
+ return succeed(stats);
190
+ });
180
191
  });
181
192
  });
182
193
  };
@@ -1,12 +1,11 @@
1
1
  import "core-js/modules/es.promise.js";
2
2
  import webpackConfig from '../preview/iframe-webpack.config';
3
- import { createPreviewEntry } from '../preview/entries';
4
3
  export var webpack = async function (_, options) {
5
4
  return webpackConfig(options);
6
5
  };
7
6
  export var entries = async function (_, options) {
8
7
  var result = [];
9
- result = result.concat(await createPreviewEntry(options));
8
+ result = result.concat(await options.presets.apply('previewEntries', [], options));
10
9
 
11
10
  if (options.configType === 'DEVELOPMENT') {
12
11
  // Suppress informational messages when --quiet is specified. webpack-hot-middleware's quiet
@@ -45,7 +45,7 @@ export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
45
45
  test: /\.(svg|ico|jpg|jpeg|png|apng|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,
46
46
  type: 'asset/resource',
47
47
  generator: {
48
- filename: isProd ? 'static/media/[name].[contenthash:8].[ext]' : 'static/media/[path][name].[ext]'
48
+ filename: isProd ? 'static/media/[name].[contenthash:8][ext]' : 'static/media/[path][name][ext]'
49
49
  }
50
50
  }, {
51
51
  test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
@@ -56,7 +56,7 @@ export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
56
56
  }
57
57
  },
58
58
  generator: {
59
- filename: isProd ? 'static/media/[name].[contenthash:8].[ext]' : 'static/media/[path][name].[ext]'
59
+ filename: isProd ? 'static/media/[name].[contenthash:8][ext]' : 'static/media/[path][name][ext]'
60
60
  }
61
61
  }]
62
62
  }),
@@ -7,7 +7,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
7
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
8
 
9
9
  import path from 'path';
10
- import fse from 'fs-extra';
11
10
  import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin } from 'webpack';
12
11
  import Dotenv from 'dotenv-webpack';
13
12
  import HtmlWebpackPlugin from 'html-webpack-plugin';
@@ -17,7 +16,7 @@ import TerserWebpackPlugin from 'terser-webpack-plugin';
17
16
  import VirtualModulePlugin from 'webpack-virtual-modules';
18
17
  import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
19
18
  import themingPaths from '@storybook/theming/paths';
20
- import { toRequireContextString, es6Transpiler, stringifyEnvs, nodeModulesPaths, interpolate, hasDotenv } from '@storybook/core-common';
19
+ import { toRequireContextString, es6Transpiler, stringifyProcessEnvs, nodeModulesPaths, handlebars, interpolate, hasDotenv, toImportFn, normalizeStories, readTemplate, loadPreviewOrConfigFile } from '@storybook/core-common';
21
20
  import { createBabelLoader } from './babel-loader-preview';
22
21
  import { useBaseTsSupport } from './useBaseTsSupport';
23
22
  var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'components', 'core-events', 'router', 'theming', 'semver', 'client-api', 'client-logger'].reduce(function (acc, sbPackage) {
@@ -25,22 +24,20 @@ var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'compo
25
24
  [`@storybook/${sbPackage}`]: path.dirname(require.resolve(`@storybook/${sbPackage}/package.json`))
26
25
  });
27
26
  }, {});
28
- export default (async function ({
29
- configDir: configDir,
30
- babelOptions: babelOptions,
31
- entries: entries,
32
- stories: stories,
33
- outputDir = path.join('.', 'public'),
34
- quiet: quiet,
35
- packageJson: packageJson,
36
- configType: configType,
37
- framework: framework,
38
- frameworkPath: frameworkPath,
39
- presets: presets,
40
- typescriptOptions: typescriptOptions,
41
- modern: modern,
42
- features: features
43
- }) {
27
+ export default (async function (options) {
28
+ var configDir = options.configDir,
29
+ babelOptions = options.babelOptions,
30
+ _options$outputDir = options.outputDir,
31
+ outputDir = _options$outputDir === void 0 ? path.join('.', 'public') : _options$outputDir,
32
+ quiet = options.quiet,
33
+ packageJson = options.packageJson,
34
+ configType = options.configType,
35
+ framework = options.framework,
36
+ frameworkPath = options.frameworkPath,
37
+ presets = options.presets,
38
+ typescriptOptions = options.typescriptOptions,
39
+ modern = options.modern,
40
+ features = options.features;
44
41
  var envs = await presets.apply('env');
45
42
  var logLevel = await presets.apply('logLevel', undefined);
46
43
  var frameworkOptions = await presets.apply(`${framework}Options`, {});
@@ -48,43 +45,55 @@ export default (async function ({
48
45
  var bodyHtmlSnippet = await presets.apply('previewBody');
49
46
  var template = await presets.apply('previewMainTemplate');
50
47
  var babelLoader = createBabelLoader(babelOptions, framework);
51
- var isProd = configType === 'PRODUCTION'; // TODO FIX ME - does this need to be ESM?
52
-
53
- var entryTemplate = await fse.readFile(path.join(__dirname, 'virtualModuleEntry.template.js'), {
54
- encoding: 'utf8'
55
- });
56
- var storyTemplate = await fse.readFile(path.join(__dirname, 'virtualModuleStory.template.js'), {
57
- encoding: 'utf8'
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 stories = normalizeStories(await presets.apply('stories', [], options), {
52
+ configDir: options.configDir,
53
+ workingDir: process.cwd()
58
54
  });
59
- var frameworkInitEntry = path.resolve(path.join(configDir, 'storybook-init-framework-entry.js')); // Allows for custom frameworks that are not published under the @storybook namespace
55
+ var virtualModuleMapping = {};
60
56
 
61
- var frameworkImportPath = frameworkPath || `@storybook/${framework}`;
62
- var virtualModuleMapping = {
63
- // Ensure that the client API is initialized by the framework before any other iframe code
64
- // is loaded. That way our client-apis can assume the existence of the API+store
65
- [frameworkInitEntry]: `import '${frameworkImportPath}';`
66
- };
67
- entries.forEach(function (entryFilename) {
68
- var match = entryFilename.match(/(.*)-generated-(config|other)-entry.js$/);
69
-
70
- if (match) {
71
- var configFilename = match[1];
57
+ if (features !== null && features !== void 0 && features.storyStoreV7) {
58
+ var storiesFilename = 'storybook-stories.js';
59
+ var storiesPath = path.resolve(path.join(configDir, storiesFilename));
60
+ virtualModuleMapping[storiesPath] = toImportFn(stories);
61
+ var configEntryPath = path.resolve(path.join(configDir, 'storybook-config-entry.js'));
62
+ virtualModuleMapping[configEntryPath] = handlebars(await readTemplate(path.join(__dirname, 'virtualModuleModernEntry.js.handlebars')), {
63
+ storiesFilename: storiesFilename,
64
+ configs: configs
65
+ });
66
+ entries.push(configEntryPath);
67
+ } else {
68
+ var frameworkInitEntry = path.resolve(path.join(configDir, 'storybook-init-framework-entry.js'));
69
+ var frameworkImportPath = frameworkPath || `@storybook/${framework}`;
70
+ virtualModuleMapping[frameworkInitEntry] = `import '${frameworkImportPath}';`;
71
+ entries.push(frameworkInitEntry);
72
+ var entryTemplate = await readTemplate(path.join(__dirname, 'virtualModuleEntry.template.js'));
73
+ configs.forEach(function (configFilename) {
72
74
  var clientApi = storybookPaths['@storybook/client-api'];
73
75
  var clientLogger = storybookPaths['@storybook/client-logger'];
74
- virtualModuleMapping[entryFilename] = interpolate(entryTemplate, {
76
+ virtualModuleMapping[`${configFilename}-generated-config-entry.js`] = interpolate(entryTemplate, {
75
77
  configFilename: configFilename,
76
78
  clientApi: clientApi,
77
79
  clientLogger: clientLogger
78
80
  });
79
- }
80
- });
81
+ entries.push(`${configFilename}-generated-config-entry.js`);
82
+ });
83
+
84
+ if (stories.length > 0) {
85
+ var storyTemplate = await readTemplate(path.join(__dirname, 'virtualModuleStory.template.js'));
81
86
 
82
- if (stories) {
83
- var storiesFilename = path.resolve(path.join(configDir, `generated-stories-entry.js`));
84
- virtualModuleMapping[storiesFilename] = interpolate(storyTemplate, {
85
- frameworkImportPath: frameworkImportPath
86
- }) // Make sure we also replace quotes for this one
87
- .replace("'{{stories}}'", stories.map(toRequireContextString).join(','));
87
+ var _storiesFilename = path.resolve(path.join(configDir, `generated-stories-entry.js`));
88
+
89
+ virtualModuleMapping[_storiesFilename] = interpolate(storyTemplate, {
90
+ frameworkImportPath: frameworkImportPath
91
+ }) // Make sure we also replace quotes for this one
92
+ .replace("'{{stories}}'", stories.map(function (s) {
93
+ return s.glob;
94
+ }).map(toRequireContextString).join(','));
95
+ entries.push(_storiesFilename);
96
+ }
88
97
  }
89
98
 
90
99
  var shouldCheckTs = useBaseTsSupport(framework) && typescriptOptions.check;
@@ -105,7 +114,6 @@ export default (async function ({
105
114
  logging: 'error'
106
115
  },
107
116
  watchOptions: {
108
- aggregateTimeout: 10,
109
117
  ignored: /node_modules/
110
118
  },
111
119
  ignoreWarnings: [{
@@ -117,16 +125,17 @@ export default (async function ({
117
125
  chunksSortMode: 'none',
118
126
  alwaysWriteToDisk: true,
119
127
  inject: false,
120
- templateParameters: function (compilation, files, options) {
128
+ templateParameters: function (compilation, files, templateOptions) {
121
129
  return {
122
130
  compilation: compilation,
123
131
  files: files,
124
- options: options,
132
+ options: templateOptions,
125
133
  version: packageJson.version,
126
134
  globals: {
127
135
  LOGLEVEL: logLevel,
128
136
  FRAMEWORK_OPTIONS: frameworkOptions,
129
- FEATURES: features
137
+ FEATURES: features,
138
+ STORIES: stories
130
139
  },
131
140
  headHtmlSnippet: headHtmlSnippet,
132
141
  bodyHtmlSnippet: bodyHtmlSnippet
@@ -141,10 +150,9 @@ export default (async function ({
141
150
  useShortDoctype: true
142
151
  },
143
152
  template: template
144
- }), new DefinePlugin({
145
- 'process.env': stringifyEnvs(envs),
153
+ }), new DefinePlugin(_objectSpread(_objectSpread({}, stringifyProcessEnvs(envs)), {}, {
146
154
  NODE_ENV: JSON.stringify(process.env.NODE_ENV)
147
- }), isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths), isProd ? null : new HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), quiet ? null : new ProgressPlugin({}), hasDotenv() ? new Dotenv({
155
+ })), isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths), isProd ? null : new HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), quiet ? null : new ProgressPlugin({}), hasDotenv() ? new Dotenv({
148
156
  silent: true
149
157
  }) : null, shouldCheckTs ? new ForkTsCheckerWebpackPlugin(tsCheckOptions) : null].filter(Boolean),
150
158
  module: {
@@ -172,6 +180,7 @@ export default (async function ({
172
180
  runtimeChunk: true,
173
181
  sideEffects: true,
174
182
  usedExports: true,
183
+ moduleIds: 'named',
175
184
  minimizer: isProd ? [new TerserWebpackPlugin({
176
185
  parallel: true,
177
186
  terserOptions: {