@storybook/builder-webpack5 6.4.0-beta.8 → 6.4.0-rc.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.
package/dist/cjs/index.js CHANGED
@@ -197,7 +197,7 @@ var build = async function ({
197
197
  return _nodeLogger.logger.error(e.message);
198
198
  });
199
199
  compiler.close(function () {
200
- return fail(stats);
200
+ return options.debugWebpack ? fail(stats) : fail(new Error('=> Webpack failed, learn more with --debug-webpack'));
201
201
  });
202
202
  return;
203
203
  }
@@ -16,7 +16,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
16
16
  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; }
17
17
 
18
18
  async function createDefaultWebpackConfig(storybookBaseConfig, options) {
19
- var _storybookBaseConfig$;
19
+ var _options, _storybookBaseConfig$;
20
20
 
21
21
  if (options.presetsList.some(function (preset) {
22
22
  return /@storybook(\/|\\)preset-create-react-app/.test(typeof preset === 'string' ? preset : preset.name);
@@ -49,6 +49,12 @@ async function createDefaultWebpackConfig(storybookBaseConfig, options) {
49
49
  }
50
50
 
51
51
  var isProd = storybookBaseConfig.mode !== 'development';
52
+ var coreOptions = await options.presets.apply('core');
53
+ var cacheConfig = (_options = coreOptions.builder.options) !== null && _options !== void 0 && _options.fsCache ? {
54
+ cache: {
55
+ type: 'filesystem'
56
+ }
57
+ } : {};
52
58
  return _objectSpread(_objectSpread({}, storybookBaseConfig), {}, {
53
59
  module: _objectSpread(_objectSpread({}, storybookBaseConfig.module), {}, {
54
60
  rules: [...storybookBaseConfig.module.rules, cssLoaders, {
@@ -76,5 +82,5 @@ async function createDefaultWebpackConfig(storybookBaseConfig, options) {
76
82
  assert: false
77
83
  })
78
84
  })
79
- });
85
+ }, cacheConfig);
80
86
  }
@@ -46,8 +46,7 @@ var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'compo
46
46
  }, {});
47
47
 
48
48
  var _default = async function _default(options) {
49
- var configDir = options.configDir,
50
- babelOptions = options.babelOptions,
49
+ var babelOptions = options.babelOptions,
51
50
  _options$outputDir = options.outputDir,
52
51
  outputDir = _options$outputDir === void 0 ? _path.default.join('.', 'public') : _options$outputDir,
53
52
  quiet = options.quiet,
@@ -58,13 +57,15 @@ var _default = async function _default(options) {
58
57
  presets = options.presets,
59
58
  typescriptOptions = options.typescriptOptions,
60
59
  modern = options.modern,
61
- features = options.features;
60
+ features = options.features,
61
+ serverChannelUrl = options.serverChannelUrl;
62
62
  var envs = await presets.apply('env');
63
63
  var logLevel = await presets.apply('logLevel', undefined);
64
64
  var frameworkOptions = await presets.apply(`${framework}Options`, {});
65
65
  var headHtmlSnippet = await presets.apply('previewHead');
66
66
  var bodyHtmlSnippet = await presets.apply('previewBody');
67
67
  var template = await presets.apply('previewMainTemplate');
68
+ var coreOptions = await presets.apply('core');
68
69
  var babelLoader = (0, _babelLoaderPreview.createBabelLoader)(babelOptions, framework);
69
70
  var isProd = configType === 'PRODUCTION';
70
71
  var configs = [...(await presets.apply('config', [], options)), (0, _coreCommon.loadPreviewOrConfigFile)(options)].filter(Boolean);
@@ -79,16 +80,17 @@ var _default = async function _default(options) {
79
80
  if (features !== null && features !== void 0 && features.storyStoreV7) {
80
81
  var storiesFilename = 'storybook-stories.js';
81
82
 
82
- var storiesPath = _path.default.resolve(_path.default.join(configDir, storiesFilename));
83
+ var storiesPath = _path.default.resolve(_path.default.join(workingDir, storiesFilename));
83
84
 
84
85
  virtualModuleMapping[storiesPath] = (0, _coreCommon.toImportFn)(stories);
85
86
 
86
- var configEntryPath = _path.default.resolve(_path.default.join(configDir, 'storybook-config-entry.js'));
87
+ var configEntryPath = _path.default.resolve(_path.default.join(workingDir, 'storybook-config-entry.js'));
87
88
 
88
89
  virtualModuleMapping[configEntryPath] = (0, _coreCommon.handlebars)(await (0, _coreCommon.readTemplate)(_path.default.join(__dirname, 'virtualModuleModernEntry.js.handlebars')), {
89
90
  storiesFilename: storiesFilename,
90
91
  configs: configs
91
- });
92
+ } // We need to double escape `\` for webpack. We may have some in windows paths
93
+ ).replace(/\\/g, '\\\\');
92
94
  entries.push(configEntryPath);
93
95
  } else {
94
96
  var frameworkInitEntry = _path.default.resolve(_path.default.join(workingDir, 'storybook-init-framework-entry.js'));
@@ -150,25 +152,24 @@ var _default = async function _default(options) {
150
152
  chunksSortMode: 'none',
151
153
  alwaysWriteToDisk: true,
152
154
  inject: false,
153
- templateParameters: function (compilation, files, templateOptions) {
154
- return {
155
- compilation: compilation,
156
- files: files,
157
- options: templateOptions,
158
- version: packageJson.version,
159
- globals: {
160
- LOGLEVEL: logLevel,
161
- FRAMEWORK_OPTIONS: frameworkOptions,
162
- FEATURES: features,
163
- STORIES: stories.map(function (specifier) {
164
- return _objectSpread(_objectSpread({}, specifier), {}, {
165
- importPathMatcher: specifier.importPathMatcher.source
166
- });
167
- })
168
- },
169
- headHtmlSnippet: headHtmlSnippet,
170
- bodyHtmlSnippet: bodyHtmlSnippet
171
- };
155
+ template: template,
156
+ templateParameters: {
157
+ version: packageJson.version,
158
+ globals: {
159
+ CONFIG_TYPE: configType,
160
+ LOGLEVEL: logLevel,
161
+ FRAMEWORK_OPTIONS: frameworkOptions,
162
+ CHANNEL_OPTIONS: coreOptions === null || coreOptions === void 0 ? void 0 : coreOptions.channelOptions,
163
+ FEATURES: features,
164
+ STORIES: stories.map(function (specifier) {
165
+ return _objectSpread(_objectSpread({}, specifier), {}, {
166
+ importPathMatcher: specifier.importPathMatcher.source
167
+ });
168
+ }),
169
+ SERVER_CHANNEL_URL: serverChannelUrl
170
+ },
171
+ headHtmlSnippet: headHtmlSnippet,
172
+ bodyHtmlSnippet: bodyHtmlSnippet
172
173
  },
173
174
  minify: {
174
175
  collapseWhitespace: true,
@@ -177,8 +178,7 @@ var _default = async function _default(options) {
177
178
  removeScriptTypeAttributes: false,
178
179
  removeStyleLinkTypeAttributes: true,
179
180
  useShortDoctype: true
180
- },
181
- template: template
181
+ }
182
182
  }), new _webpack.DefinePlugin(_objectSpread(_objectSpread({}, (0, _coreCommon.stringifyProcessEnvs)(envs)), {}, {
183
183
  NODE_ENV: JSON.stringify(process.env.NODE_ENV)
184
184
  })), isProd ? null : new _WatchMissingNodeModulesPlugin.default(_coreCommon.nodeModulesPaths), isProd ? null : new _webpack.HotModuleReplacementPlugin(), new _caseSensitivePathsWebpackPlugin.default(), quiet ? null : new _webpack.ProgressPlugin({}), shouldCheckTs ? new _forkTsCheckerWebpackPlugin.default(tsCheckOptions) : null].filter(Boolean),
@@ -192,7 +192,7 @@ var _default = async function _default(options) {
192
192
  extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
193
193
  modules: ['node_modules'].concat(envs.NODE_PATH || []),
194
194
  mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
195
- alias: _objectSpread(_objectSpread(_objectSpread({}, _paths.default), storybookPaths), {}, {
195
+ alias: _objectSpread(_objectSpread(_objectSpread({}, features !== null && features !== void 0 && features.emotionAlias ? _paths.default : {}), storybookPaths), {}, {
196
196
  react: _path.default.dirname(require.resolve('react/package.json')),
197
197
  'react-dom': _path.default.dirname(require.resolve('react-dom/package.json'))
198
198
  }),
@@ -64,6 +64,12 @@ Object.keys(config).forEach(function (key) {
64
64
  return addParameters(v, false);
65
65
  }
66
66
 
67
+ case 'decorateStory':
68
+ case 'renderToDOM':
69
+ {
70
+ return null; // This key is not handled directly in v6 mode.
71
+ }
72
+
67
73
  default:
68
74
  {
69
75
  // eslint-disable-next-line prefer-template
@@ -1,22 +1,28 @@
1
1
  import fetch from 'unfetch';
2
+ import global from 'global';
2
3
 
3
- import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
4
- import { ClientApi } from '@storybook/client-api';
4
+ import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
5
+ import { ClientApi } from '@storybook/client-api';
5
6
  import { addons } from '@storybook/addons';
6
- import createChannel from '@storybook/channel-postmessage';
7
+ import createPostMessageChannel from '@storybook/channel-postmessage';
8
+ import createWebSocketChannel from '@storybook/channel-websocket';
7
9
 
8
10
  import { importFn } from './{{storiesFilename}}';
9
11
 
12
+ const { SERVER_CHANNEL_URL } = global;
13
+
10
14
  const getProjectAnnotations = () =>
11
- composeConfigs([
12
- {{#each configs}}
13
- require('{{this}}'),
14
- {{/each}}
15
- ]);
15
+ composeConfigs([{{#each configs}}require('{{this}}'),{{/each}}]);
16
16
 
17
- const channel = createChannel({ page: 'preview' });
17
+ const channel = createPostMessageChannel({ page: 'preview' });
18
18
  addons.setChannel(channel);
19
19
 
20
+ if (SERVER_CHANNEL_URL) {
21
+ const serverChannel = createWebSocketChannel({ url: SERVER_CHANNEL_URL, });
22
+ addons.setServerChannel(serverChannel);
23
+ window.__STORYBOOK_SERVER_CHANNEL__ = serverChannel;
24
+ }
25
+
20
26
  const preview = new PreviewWeb();
21
27
 
22
28
  window.__STORYBOOK_PREVIEW__ = preview;
@@ -36,4 +42,4 @@ if (module.hot) {
36
42
  // getProjectAnnotations has changed so we need to patch the new one in
37
43
  preview.onGetProjectAnnotationsChanged({ getProjectAnnotations });
38
44
  });
39
- }
45
+ }
package/dist/esm/index.js CHANGED
@@ -160,7 +160,7 @@ export var build = async function ({
160
160
  return logger.error(e.message);
161
161
  });
162
162
  compiler.close(function () {
163
- return fail(stats);
163
+ return options.debugWebpack ? fail(stats) : fail(new Error('=> Webpack failed, learn more with --debug-webpack'));
164
164
  });
165
165
  return;
166
166
  }
@@ -7,7 +7,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
7
7
  import "core-js/modules/es.promise.js";
8
8
  import { logger } from '@storybook/node-logger';
9
9
  export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
10
- var _storybookBaseConfig$;
10
+ var _options, _storybookBaseConfig$;
11
11
 
12
12
  if (options.presetsList.some(function (preset) {
13
13
  return /@storybook(\/|\\)preset-create-react-app/.test(typeof preset === 'string' ? preset : preset.name);
@@ -39,6 +39,12 @@ export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
39
39
  }
40
40
 
41
41
  var isProd = storybookBaseConfig.mode !== 'development';
42
+ var coreOptions = await options.presets.apply('core');
43
+ var cacheConfig = (_options = coreOptions.builder.options) !== null && _options !== void 0 && _options.fsCache ? {
44
+ cache: {
45
+ type: 'filesystem'
46
+ }
47
+ } : {};
42
48
  return _objectSpread(_objectSpread({}, storybookBaseConfig), {}, {
43
49
  module: _objectSpread(_objectSpread({}, storybookBaseConfig.module), {}, {
44
50
  rules: [...storybookBaseConfig.module.rules, cssLoaders, {
@@ -66,5 +72,5 @@ export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
66
72
  assert: false
67
73
  })
68
74
  })
69
- });
75
+ }, cacheConfig);
70
76
  }
@@ -24,8 +24,7 @@ var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'compo
24
24
  });
25
25
  }, {});
26
26
  export default (async function (options) {
27
- var configDir = options.configDir,
28
- babelOptions = options.babelOptions,
27
+ var babelOptions = options.babelOptions,
29
28
  _options$outputDir = options.outputDir,
30
29
  outputDir = _options$outputDir === void 0 ? path.join('.', 'public') : _options$outputDir,
31
30
  quiet = options.quiet,
@@ -36,13 +35,15 @@ export default (async function (options) {
36
35
  presets = options.presets,
37
36
  typescriptOptions = options.typescriptOptions,
38
37
  modern = options.modern,
39
- features = options.features;
38
+ features = options.features,
39
+ serverChannelUrl = options.serverChannelUrl;
40
40
  var envs = await presets.apply('env');
41
41
  var logLevel = await presets.apply('logLevel', undefined);
42
42
  var frameworkOptions = await presets.apply(`${framework}Options`, {});
43
43
  var headHtmlSnippet = await presets.apply('previewHead');
44
44
  var bodyHtmlSnippet = await presets.apply('previewBody');
45
45
  var template = await presets.apply('previewMainTemplate');
46
+ var coreOptions = await presets.apply('core');
46
47
  var babelLoader = createBabelLoader(babelOptions, framework);
47
48
  var isProd = configType === 'PRODUCTION';
48
49
  var configs = [...(await presets.apply('config', [], options)), loadPreviewOrConfigFile(options)].filter(Boolean);
@@ -56,13 +57,14 @@ export default (async function (options) {
56
57
 
57
58
  if (features !== null && features !== void 0 && features.storyStoreV7) {
58
59
  var storiesFilename = 'storybook-stories.js';
59
- var storiesPath = path.resolve(path.join(configDir, storiesFilename));
60
+ var storiesPath = path.resolve(path.join(workingDir, storiesFilename));
60
61
  virtualModuleMapping[storiesPath] = toImportFn(stories);
61
- var configEntryPath = path.resolve(path.join(configDir, 'storybook-config-entry.js'));
62
+ var configEntryPath = path.resolve(path.join(workingDir, 'storybook-config-entry.js'));
62
63
  virtualModuleMapping[configEntryPath] = handlebars(await readTemplate(path.join(__dirname, 'virtualModuleModernEntry.js.handlebars')), {
63
64
  storiesFilename: storiesFilename,
64
65
  configs: configs
65
- });
66
+ } // We need to double escape `\` for webpack. We may have some in windows paths
67
+ ).replace(/\\/g, '\\\\');
66
68
  entries.push(configEntryPath);
67
69
  } else {
68
70
  var frameworkInitEntry = path.resolve(path.join(workingDir, 'storybook-init-framework-entry.js'));
@@ -123,25 +125,24 @@ export default (async function (options) {
123
125
  chunksSortMode: 'none',
124
126
  alwaysWriteToDisk: true,
125
127
  inject: false,
126
- templateParameters: function (compilation, files, templateOptions) {
127
- return {
128
- compilation: compilation,
129
- files: files,
130
- options: templateOptions,
131
- version: packageJson.version,
132
- globals: {
133
- LOGLEVEL: logLevel,
134
- FRAMEWORK_OPTIONS: frameworkOptions,
135
- FEATURES: features,
136
- STORIES: stories.map(function (specifier) {
137
- return _objectSpread(_objectSpread({}, specifier), {}, {
138
- importPathMatcher: specifier.importPathMatcher.source
139
- });
140
- })
141
- },
142
- headHtmlSnippet: headHtmlSnippet,
143
- bodyHtmlSnippet: bodyHtmlSnippet
144
- };
128
+ template: template,
129
+ templateParameters: {
130
+ version: packageJson.version,
131
+ globals: {
132
+ CONFIG_TYPE: configType,
133
+ LOGLEVEL: logLevel,
134
+ FRAMEWORK_OPTIONS: frameworkOptions,
135
+ CHANNEL_OPTIONS: coreOptions === null || coreOptions === void 0 ? void 0 : coreOptions.channelOptions,
136
+ FEATURES: features,
137
+ STORIES: stories.map(function (specifier) {
138
+ return _objectSpread(_objectSpread({}, specifier), {}, {
139
+ importPathMatcher: specifier.importPathMatcher.source
140
+ });
141
+ }),
142
+ SERVER_CHANNEL_URL: serverChannelUrl
143
+ },
144
+ headHtmlSnippet: headHtmlSnippet,
145
+ bodyHtmlSnippet: bodyHtmlSnippet
145
146
  },
146
147
  minify: {
147
148
  collapseWhitespace: true,
@@ -150,8 +151,7 @@ export default (async function (options) {
150
151
  removeScriptTypeAttributes: false,
151
152
  removeStyleLinkTypeAttributes: true,
152
153
  useShortDoctype: true
153
- },
154
- template: template
154
+ }
155
155
  }), new DefinePlugin(_objectSpread(_objectSpread({}, stringifyProcessEnvs(envs)), {}, {
156
156
  NODE_ENV: JSON.stringify(process.env.NODE_ENV)
157
157
  })), isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths), isProd ? null : new HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), quiet ? null : new ProgressPlugin({}), shouldCheckTs ? new ForkTsCheckerWebpackPlugin(tsCheckOptions) : null].filter(Boolean),
@@ -165,7 +165,7 @@ export default (async function (options) {
165
165
  extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
166
166
  modules: ['node_modules'].concat(envs.NODE_PATH || []),
167
167
  mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
168
- alias: _objectSpread(_objectSpread(_objectSpread({}, themingPaths), storybookPaths), {}, {
168
+ alias: _objectSpread(_objectSpread(_objectSpread({}, features !== null && features !== void 0 && features.emotionAlias ? themingPaths : {}), storybookPaths), {}, {
169
169
  react: path.dirname(require.resolve('react/package.json')),
170
170
  'react-dom': path.dirname(require.resolve('react-dom/package.json'))
171
171
  }),
@@ -64,6 +64,12 @@ Object.keys(config).forEach(function (key) {
64
64
  return addParameters(v, false);
65
65
  }
66
66
 
67
+ case 'decorateStory':
68
+ case 'renderToDOM':
69
+ {
70
+ return null; // This key is not handled directly in v6 mode.
71
+ }
72
+
67
73
  default:
68
74
  {
69
75
  // eslint-disable-next-line prefer-template
@@ -1,22 +1,28 @@
1
1
  import fetch from 'unfetch';
2
+ import global from 'global';
2
3
 
3
- import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
4
- import { ClientApi } from '@storybook/client-api';
4
+ import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
5
+ import { ClientApi } from '@storybook/client-api';
5
6
  import { addons } from '@storybook/addons';
6
- import createChannel from '@storybook/channel-postmessage';
7
+ import createPostMessageChannel from '@storybook/channel-postmessage';
8
+ import createWebSocketChannel from '@storybook/channel-websocket';
7
9
 
8
10
  import { importFn } from './{{storiesFilename}}';
9
11
 
12
+ const { SERVER_CHANNEL_URL } = global;
13
+
10
14
  const getProjectAnnotations = () =>
11
- composeConfigs([
12
- {{#each configs}}
13
- require('{{this}}'),
14
- {{/each}}
15
- ]);
15
+ composeConfigs([{{#each configs}}require('{{this}}'),{{/each}}]);
16
16
 
17
- const channel = createChannel({ page: 'preview' });
17
+ const channel = createPostMessageChannel({ page: 'preview' });
18
18
  addons.setChannel(channel);
19
19
 
20
+ if (SERVER_CHANNEL_URL) {
21
+ const serverChannel = createWebSocketChannel({ url: SERVER_CHANNEL_URL, });
22
+ addons.setServerChannel(serverChannel);
23
+ window.__STORYBOOK_SERVER_CHANNEL__ = serverChannel;
24
+ }
25
+
20
26
  const preview = new PreviewWeb();
21
27
 
22
28
  window.__STORYBOOK_PREVIEW__ = preview;
@@ -36,4 +42,4 @@ if (module.hot) {
36
42
  // getProjectAnnotations has changed so we need to patch the new one in
37
43
  preview.onGetProjectAnnotationsChanged({ getProjectAnnotations });
38
44
  });
39
- }
45
+ }
@@ -160,7 +160,7 @@ export var build = async function ({
160
160
  return logger.error(e.message);
161
161
  });
162
162
  compiler.close(function () {
163
- return fail(stats);
163
+ return options.debugWebpack ? fail(stats) : fail(new Error('=> Webpack failed, learn more with --debug-webpack'));
164
164
  });
165
165
  return;
166
166
  }
@@ -7,7 +7,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
7
7
  import "core-js/modules/es.promise.js";
8
8
  import { logger } from '@storybook/node-logger';
9
9
  export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
10
- var _storybookBaseConfig$;
10
+ var _options, _storybookBaseConfig$;
11
11
 
12
12
  if (options.presetsList.some(function (preset) {
13
13
  return /@storybook(\/|\\)preset-create-react-app/.test(typeof preset === 'string' ? preset : preset.name);
@@ -39,6 +39,12 @@ export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
39
39
  }
40
40
 
41
41
  var isProd = storybookBaseConfig.mode !== 'development';
42
+ var coreOptions = await options.presets.apply('core');
43
+ var cacheConfig = (_options = coreOptions.builder.options) !== null && _options !== void 0 && _options.fsCache ? {
44
+ cache: {
45
+ type: 'filesystem'
46
+ }
47
+ } : {};
42
48
  return _objectSpread(_objectSpread({}, storybookBaseConfig), {}, {
43
49
  module: _objectSpread(_objectSpread({}, storybookBaseConfig.module), {}, {
44
50
  rules: [...storybookBaseConfig.module.rules, cssLoaders, {
@@ -66,5 +72,5 @@ export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
66
72
  assert: false
67
73
  })
68
74
  })
69
- });
75
+ }, cacheConfig);
70
76
  }
@@ -24,8 +24,7 @@ var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'compo
24
24
  });
25
25
  }, {});
26
26
  export default (async function (options) {
27
- var configDir = options.configDir,
28
- babelOptions = options.babelOptions,
27
+ var babelOptions = options.babelOptions,
29
28
  _options$outputDir = options.outputDir,
30
29
  outputDir = _options$outputDir === void 0 ? path.join('.', 'public') : _options$outputDir,
31
30
  quiet = options.quiet,
@@ -36,13 +35,15 @@ export default (async function (options) {
36
35
  presets = options.presets,
37
36
  typescriptOptions = options.typescriptOptions,
38
37
  modern = options.modern,
39
- features = options.features;
38
+ features = options.features,
39
+ serverChannelUrl = options.serverChannelUrl;
40
40
  var envs = await presets.apply('env');
41
41
  var logLevel = await presets.apply('logLevel', undefined);
42
42
  var frameworkOptions = await presets.apply(`${framework}Options`, {});
43
43
  var headHtmlSnippet = await presets.apply('previewHead');
44
44
  var bodyHtmlSnippet = await presets.apply('previewBody');
45
45
  var template = await presets.apply('previewMainTemplate');
46
+ var coreOptions = await presets.apply('core');
46
47
  var babelLoader = createBabelLoader(babelOptions, framework);
47
48
  var isProd = configType === 'PRODUCTION';
48
49
  var configs = [...(await presets.apply('config', [], options)), loadPreviewOrConfigFile(options)].filter(Boolean);
@@ -56,13 +57,14 @@ export default (async function (options) {
56
57
 
57
58
  if (features !== null && features !== void 0 && features.storyStoreV7) {
58
59
  var storiesFilename = 'storybook-stories.js';
59
- var storiesPath = path.resolve(path.join(configDir, storiesFilename));
60
+ var storiesPath = path.resolve(path.join(workingDir, storiesFilename));
60
61
  virtualModuleMapping[storiesPath] = toImportFn(stories);
61
- var configEntryPath = path.resolve(path.join(configDir, 'storybook-config-entry.js'));
62
+ var configEntryPath = path.resolve(path.join(workingDir, 'storybook-config-entry.js'));
62
63
  virtualModuleMapping[configEntryPath] = handlebars(await readTemplate(path.join(__dirname, 'virtualModuleModernEntry.js.handlebars')), {
63
64
  storiesFilename: storiesFilename,
64
65
  configs: configs
65
- });
66
+ } // We need to double escape `\` for webpack. We may have some in windows paths
67
+ ).replace(/\\/g, '\\\\');
66
68
  entries.push(configEntryPath);
67
69
  } else {
68
70
  var frameworkInitEntry = path.resolve(path.join(workingDir, 'storybook-init-framework-entry.js'));
@@ -123,25 +125,24 @@ export default (async function (options) {
123
125
  chunksSortMode: 'none',
124
126
  alwaysWriteToDisk: true,
125
127
  inject: false,
126
- templateParameters: function (compilation, files, templateOptions) {
127
- return {
128
- compilation: compilation,
129
- files: files,
130
- options: templateOptions,
131
- version: packageJson.version,
132
- globals: {
133
- LOGLEVEL: logLevel,
134
- FRAMEWORK_OPTIONS: frameworkOptions,
135
- FEATURES: features,
136
- STORIES: stories.map(function (specifier) {
137
- return _objectSpread(_objectSpread({}, specifier), {}, {
138
- importPathMatcher: specifier.importPathMatcher.source
139
- });
140
- })
141
- },
142
- headHtmlSnippet: headHtmlSnippet,
143
- bodyHtmlSnippet: bodyHtmlSnippet
144
- };
128
+ template: template,
129
+ templateParameters: {
130
+ version: packageJson.version,
131
+ globals: {
132
+ CONFIG_TYPE: configType,
133
+ LOGLEVEL: logLevel,
134
+ FRAMEWORK_OPTIONS: frameworkOptions,
135
+ CHANNEL_OPTIONS: coreOptions === null || coreOptions === void 0 ? void 0 : coreOptions.channelOptions,
136
+ FEATURES: features,
137
+ STORIES: stories.map(function (specifier) {
138
+ return _objectSpread(_objectSpread({}, specifier), {}, {
139
+ importPathMatcher: specifier.importPathMatcher.source
140
+ });
141
+ }),
142
+ SERVER_CHANNEL_URL: serverChannelUrl
143
+ },
144
+ headHtmlSnippet: headHtmlSnippet,
145
+ bodyHtmlSnippet: bodyHtmlSnippet
145
146
  },
146
147
  minify: {
147
148
  collapseWhitespace: true,
@@ -150,8 +151,7 @@ export default (async function (options) {
150
151
  removeScriptTypeAttributes: false,
151
152
  removeStyleLinkTypeAttributes: true,
152
153
  useShortDoctype: true
153
- },
154
- template: template
154
+ }
155
155
  }), new DefinePlugin(_objectSpread(_objectSpread({}, stringifyProcessEnvs(envs)), {}, {
156
156
  NODE_ENV: JSON.stringify(process.env.NODE_ENV)
157
157
  })), isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths), isProd ? null : new HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), quiet ? null : new ProgressPlugin({}), shouldCheckTs ? new ForkTsCheckerWebpackPlugin(tsCheckOptions) : null].filter(Boolean),
@@ -165,7 +165,7 @@ export default (async function (options) {
165
165
  extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
166
166
  modules: ['node_modules'].concat(envs.NODE_PATH || []),
167
167
  mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
168
- alias: _objectSpread(_objectSpread(_objectSpread({}, themingPaths), storybookPaths), {}, {
168
+ alias: _objectSpread(_objectSpread(_objectSpread({}, features !== null && features !== void 0 && features.emotionAlias ? themingPaths : {}), storybookPaths), {}, {
169
169
  react: path.dirname(require.resolve('react/package.json')),
170
170
  'react-dom': path.dirname(require.resolve('react-dom/package.json'))
171
171
  }),
@@ -64,6 +64,12 @@ Object.keys(config).forEach(function (key) {
64
64
  return addParameters(v, false);
65
65
  }
66
66
 
67
+ case 'decorateStory':
68
+ case 'renderToDOM':
69
+ {
70
+ return null; // This key is not handled directly in v6 mode.
71
+ }
72
+
67
73
  default:
68
74
  {
69
75
  // eslint-disable-next-line prefer-template
@@ -1,22 +1,28 @@
1
1
  import fetch from 'unfetch';
2
+ import global from 'global';
2
3
 
3
- import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
4
- import { ClientApi } from '@storybook/client-api';
4
+ import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
5
+ import { ClientApi } from '@storybook/client-api';
5
6
  import { addons } from '@storybook/addons';
6
- import createChannel from '@storybook/channel-postmessage';
7
+ import createPostMessageChannel from '@storybook/channel-postmessage';
8
+ import createWebSocketChannel from '@storybook/channel-websocket';
7
9
 
8
10
  import { importFn } from './{{storiesFilename}}';
9
11
 
12
+ const { SERVER_CHANNEL_URL } = global;
13
+
10
14
  const getProjectAnnotations = () =>
11
- composeConfigs([
12
- {{#each configs}}
13
- require('{{this}}'),
14
- {{/each}}
15
- ]);
15
+ composeConfigs([{{#each configs}}require('{{this}}'),{{/each}}]);
16
16
 
17
- const channel = createChannel({ page: 'preview' });
17
+ const channel = createPostMessageChannel({ page: 'preview' });
18
18
  addons.setChannel(channel);
19
19
 
20
+ if (SERVER_CHANNEL_URL) {
21
+ const serverChannel = createWebSocketChannel({ url: SERVER_CHANNEL_URL, });
22
+ addons.setServerChannel(serverChannel);
23
+ window.__STORYBOOK_SERVER_CHANNEL__ = serverChannel;
24
+ }
25
+
20
26
  const preview = new PreviewWeb();
21
27
 
22
28
  window.__STORYBOOK_PREVIEW__ = preview;
@@ -36,4 +42,4 @@ if (module.hot) {
36
42
  // getProjectAnnotations has changed so we need to patch the new one in
37
43
  preview.onGetProjectAnnotationsChanged({ getProjectAnnotations });
38
44
  });
39
- }
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-webpack5",
3
- "version": "6.4.0-beta.8",
3
+ "version": "6.4.0-rc.2",
4
4
  "description": "Storybook framework-agnostic API",
5
5
  "keywords": [
6
6
  "storybook"
@@ -60,21 +60,21 @@
60
60
  "@babel/preset-env": "^7.12.11",
61
61
  "@babel/preset-react": "^7.12.10",
62
62
  "@babel/preset-typescript": "^7.12.7",
63
- "@storybook/addons": "6.4.0-beta.8",
64
- "@storybook/api": "6.4.0-beta.8",
65
- "@storybook/channel-postmessage": "6.4.0-beta.8",
66
- "@storybook/channels": "6.4.0-beta.8",
67
- "@storybook/client-api": "6.4.0-beta.8",
68
- "@storybook/client-logger": "6.4.0-beta.8",
69
- "@storybook/components": "6.4.0-beta.8",
70
- "@storybook/core-common": "6.4.0-beta.8",
71
- "@storybook/core-events": "6.4.0-beta.8",
72
- "@storybook/node-logger": "6.4.0-beta.8",
73
- "@storybook/preview-web": "6.4.0-beta.8",
74
- "@storybook/router": "6.4.0-beta.8",
63
+ "@storybook/addons": "6.4.0-rc.2",
64
+ "@storybook/api": "6.4.0-rc.2",
65
+ "@storybook/channel-postmessage": "6.4.0-rc.2",
66
+ "@storybook/channels": "6.4.0-rc.2",
67
+ "@storybook/client-api": "6.4.0-rc.2",
68
+ "@storybook/client-logger": "6.4.0-rc.2",
69
+ "@storybook/components": "6.4.0-rc.2",
70
+ "@storybook/core-common": "6.4.0-rc.2",
71
+ "@storybook/core-events": "6.4.0-rc.2",
72
+ "@storybook/node-logger": "6.4.0-rc.2",
73
+ "@storybook/preview-web": "6.4.0-rc.2",
74
+ "@storybook/router": "6.4.0-rc.2",
75
75
  "@storybook/semver": "^7.3.2",
76
- "@storybook/store": "6.4.0-beta.8",
77
- "@storybook/theming": "6.4.0-beta.8",
76
+ "@storybook/store": "6.4.0-rc.2",
77
+ "@storybook/theming": "6.4.0-rc.2",
78
78
  "@types/node": "^14.0.10",
79
79
  "babel-loader": "^8.0.0",
80
80
  "babel-plugin-macros": "^3.0.1",
@@ -117,6 +117,6 @@
117
117
  "publishConfig": {
118
118
  "access": "public"
119
119
  },
120
- "gitHead": "7f1ecb08225a3f146f9d6013a89e2a6d4d3dcd11",
120
+ "gitHead": "16be10b522569b4b55c684e1556b91b300009bf4",
121
121
  "sbmodern": "dist/modern/index.js"
122
122
  }