@storybook/builder-webpack5 6.4.0-beta.9 → 6.4.0-rc.11
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/preview/base-webpack.config.js +8 -2
- package/dist/cjs/preview/iframe-webpack.config.js +31 -29
- package/dist/cjs/preview/virtualModuleEntry.template.js +6 -0
- package/dist/cjs/preview/virtualModuleModernEntry.js.handlebars +16 -10
- package/dist/esm/preview/base-webpack.config.js +8 -2
- package/dist/esm/preview/iframe-webpack.config.js +32 -30
- package/dist/esm/preview/virtualModuleEntry.template.js +6 -0
- package/dist/esm/preview/virtualModuleModernEntry.js.handlebars +16 -10
- package/dist/modern/preview/base-webpack.config.js +8 -2
- package/dist/modern/preview/iframe-webpack.config.js +32 -30
- package/dist/modern/preview/virtualModuleEntry.template.js +6 -0
- package/dist/modern/preview/virtualModuleModernEntry.js.handlebars +16 -10
- package/package.json +16 -16
|
@@ -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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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,11 +178,12 @@ 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
|
+
})), new _webpack.ProvidePlugin({
|
|
185
|
+
process: 'process/browser.js'
|
|
186
|
+
}), 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),
|
|
185
187
|
module: {
|
|
186
188
|
rules: [babelLoader, (0, _coreCommon.es6Transpiler)(), {
|
|
187
189
|
test: /\.md$/,
|
|
@@ -192,7 +194,7 @@ var _default = async function _default(options) {
|
|
|
192
194
|
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
|
|
193
195
|
modules: ['node_modules'].concat(envs.NODE_PATH || []),
|
|
194
196
|
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
|
|
195
|
-
alias: _objectSpread(_objectSpread(_objectSpread({}, _paths.default), storybookPaths), {}, {
|
|
197
|
+
alias: _objectSpread(_objectSpread(_objectSpread({}, features !== null && features !== void 0 && features.emotionAlias ? _paths.default : {}), storybookPaths), {}, {
|
|
196
198
|
react: _path.default.dirname(require.resolve('react/package.json')),
|
|
197
199
|
'react-dom': _path.default.dirname(require.resolve('react-dom/package.json'))
|
|
198
200
|
}),
|
|
@@ -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
|
|
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 =
|
|
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
|
+
}
|
|
@@ -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
|
}
|
|
@@ -7,7 +7,7 @@ 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 { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin } from 'webpack';
|
|
10
|
+
import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';
|
|
11
11
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
12
12
|
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
|
|
13
13
|
import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin';
|
|
@@ -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
|
|
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(
|
|
60
|
+
var storiesPath = path.resolve(path.join(workingDir, storiesFilename));
|
|
60
61
|
virtualModuleMapping[storiesPath] = toImportFn(stories);
|
|
61
|
-
var configEntryPath = path.resolve(path.join(
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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,11 +151,12 @@ 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
|
+
})), new ProvidePlugin({
|
|
158
|
+
process: 'process/browser.js'
|
|
159
|
+
}), isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths), isProd ? null : new HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), quiet ? null : new ProgressPlugin({}), shouldCheckTs ? new ForkTsCheckerWebpackPlugin(tsCheckOptions) : null].filter(Boolean),
|
|
158
160
|
module: {
|
|
159
161
|
rules: [babelLoader, es6Transpiler(), {
|
|
160
162
|
test: /\.md$/,
|
|
@@ -165,7 +167,7 @@ export default (async function (options) {
|
|
|
165
167
|
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
|
|
166
168
|
modules: ['node_modules'].concat(envs.NODE_PATH || []),
|
|
167
169
|
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
|
|
168
|
-
alias: _objectSpread(_objectSpread(_objectSpread({}, themingPaths), storybookPaths), {}, {
|
|
170
|
+
alias: _objectSpread(_objectSpread(_objectSpread({}, features !== null && features !== void 0 && features.emotionAlias ? themingPaths : {}), storybookPaths), {}, {
|
|
169
171
|
react: path.dirname(require.resolve('react/package.json')),
|
|
170
172
|
'react-dom': path.dirname(require.resolve('react-dom/package.json'))
|
|
171
173
|
}),
|
|
@@ -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
|
|
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 =
|
|
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
|
+
}
|
|
@@ -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
|
}
|
|
@@ -7,7 +7,7 @@ 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 { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin } from 'webpack';
|
|
10
|
+
import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';
|
|
11
11
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
12
12
|
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
|
|
13
13
|
import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin';
|
|
@@ -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
|
|
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(
|
|
60
|
+
var storiesPath = path.resolve(path.join(workingDir, storiesFilename));
|
|
60
61
|
virtualModuleMapping[storiesPath] = toImportFn(stories);
|
|
61
|
-
var configEntryPath = path.resolve(path.join(
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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,11 +151,12 @@ 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
|
+
})), new ProvidePlugin({
|
|
158
|
+
process: 'process/browser.js'
|
|
159
|
+
}), isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths), isProd ? null : new HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), quiet ? null : new ProgressPlugin({}), shouldCheckTs ? new ForkTsCheckerWebpackPlugin(tsCheckOptions) : null].filter(Boolean),
|
|
158
160
|
module: {
|
|
159
161
|
rules: [babelLoader, es6Transpiler(), {
|
|
160
162
|
test: /\.md$/,
|
|
@@ -165,7 +167,7 @@ export default (async function (options) {
|
|
|
165
167
|
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
|
|
166
168
|
modules: ['node_modules'].concat(envs.NODE_PATH || []),
|
|
167
169
|
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
|
|
168
|
-
alias: _objectSpread(_objectSpread(_objectSpread({}, themingPaths), storybookPaths), {}, {
|
|
170
|
+
alias: _objectSpread(_objectSpread(_objectSpread({}, features !== null && features !== void 0 && features.emotionAlias ? themingPaths : {}), storybookPaths), {}, {
|
|
169
171
|
react: path.dirname(require.resolve('react/package.json')),
|
|
170
172
|
'react-dom': path.dirname(require.resolve('react-dom/package.json'))
|
|
171
173
|
}),
|
|
@@ -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
|
|
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 =
|
|
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-
|
|
3
|
+
"version": "6.4.0-rc.11",
|
|
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-
|
|
64
|
-
"@storybook/api": "6.4.0-
|
|
65
|
-
"@storybook/channel-postmessage": "6.4.0-
|
|
66
|
-
"@storybook/channels": "6.4.0-
|
|
67
|
-
"@storybook/client-api": "6.4.0-
|
|
68
|
-
"@storybook/client-logger": "6.4.0-
|
|
69
|
-
"@storybook/components": "6.4.0-
|
|
70
|
-
"@storybook/core-common": "6.4.0-
|
|
71
|
-
"@storybook/core-events": "6.4.0-
|
|
72
|
-
"@storybook/node-logger": "6.4.0-
|
|
73
|
-
"@storybook/preview-web": "6.4.0-
|
|
74
|
-
"@storybook/router": "6.4.0-
|
|
63
|
+
"@storybook/addons": "6.4.0-rc.11",
|
|
64
|
+
"@storybook/api": "6.4.0-rc.11",
|
|
65
|
+
"@storybook/channel-postmessage": "6.4.0-rc.11",
|
|
66
|
+
"@storybook/channels": "6.4.0-rc.11",
|
|
67
|
+
"@storybook/client-api": "6.4.0-rc.11",
|
|
68
|
+
"@storybook/client-logger": "6.4.0-rc.11",
|
|
69
|
+
"@storybook/components": "6.4.0-rc.11",
|
|
70
|
+
"@storybook/core-common": "6.4.0-rc.11",
|
|
71
|
+
"@storybook/core-events": "6.4.0-rc.11",
|
|
72
|
+
"@storybook/node-logger": "6.4.0-rc.11",
|
|
73
|
+
"@storybook/preview-web": "6.4.0-rc.11",
|
|
74
|
+
"@storybook/router": "6.4.0-rc.11",
|
|
75
75
|
"@storybook/semver": "^7.3.2",
|
|
76
|
-
"@storybook/store": "6.4.0-
|
|
77
|
-
"@storybook/theming": "6.4.0-
|
|
76
|
+
"@storybook/store": "6.4.0-rc.11",
|
|
77
|
+
"@storybook/theming": "6.4.0-rc.11",
|
|
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": "
|
|
120
|
+
"gitHead": "77eb43c5f02179fb2a823f975448e706710931fc",
|
|
121
121
|
"sbmodern": "dist/modern/index.js"
|
|
122
122
|
}
|