@storybook/builder-webpack5 10.1.0-alpha.9 → 10.1.0-beta.1
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/_node-chunks/chunk-CAP7MRPN.js +60 -0
- package/dist/_node-chunks/chunk-TOVLNAI6.js +45 -0
- package/dist/index.js +610 -912
- package/dist/loaders/export-order-loader.js +15 -22
- package/dist/loaders/storybook-mock-transform-loader.js +29 -0
- package/dist/loaders/webpack-automock-loader.js +22 -0
- package/dist/presets/custom-webpack-preset.js +192 -73
- package/dist/presets/preview-preset.js +51 -71
- package/package.json +7 -4
- package/dist/_node-chunks/chunk-VEIR4MFH.js +0 -50
- package/dist/_node-chunks/chunk-ZH33Z335.js +0 -85
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_igzmuwopv from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_igzmuwopv from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_igzmuwopv from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_igzmuwopv.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_igzmuwopv.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_igzmuwopv.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
|
-
import
|
|
13
|
-
__name
|
|
14
|
-
} from "../_node-chunks/chunk-VEIR4MFH.js";
|
|
12
|
+
import "../_node-chunks/chunk-TOVLNAI6.js";
|
|
15
13
|
|
|
16
14
|
// src/loaders/export-order-loader.ts
|
|
17
15
|
import assert from "node:assert";
|
|
@@ -19,40 +17,35 @@ import { init as initCjsParser, parse as parseCjs } from "cjs-module-lexer";
|
|
|
19
17
|
import { parse as parseEs } from "es-module-lexer";
|
|
20
18
|
import MagicString from "magic-string";
|
|
21
19
|
async function loader(source, map, meta) {
|
|
22
|
-
|
|
20
|
+
let callback = this.async();
|
|
23
21
|
try {
|
|
24
|
-
|
|
25
|
-
if (!source.includes("__namedExportsOrder"))
|
|
22
|
+
let magicString = new MagicString(source);
|
|
23
|
+
if (!source.includes("__namedExportsOrder"))
|
|
26
24
|
try {
|
|
27
|
-
|
|
28
|
-
const namedExportsOrder = (parseResult[1] || []).map((e) => source.substring(e.s, e.e)).filter((e) => e !== "default");
|
|
25
|
+
let namedExportsOrder = ((await parseEs(source))[1] || []).map((e) => source.substring(e.s, e.e)).filter((e) => e !== "default");
|
|
29
26
|
assert(
|
|
30
27
|
namedExportsOrder.length > 0,
|
|
31
28
|
"No named exports found. Very likely that this is not a ES module."
|
|
32
|
-
)
|
|
33
|
-
magicString.append(
|
|
29
|
+
), magicString.append(
|
|
34
30
|
`;export const __namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
|
|
35
31
|
);
|
|
36
32
|
} catch {
|
|
37
33
|
await initCjsParser();
|
|
38
|
-
|
|
34
|
+
let namedExportsOrder = (parseCjs(source).exports || []).filter(
|
|
39
35
|
(e) => e !== "default" && e !== "__esModule"
|
|
40
36
|
);
|
|
41
37
|
assert(
|
|
42
38
|
namedExportsOrder.length > 0,
|
|
43
39
|
"No named exports found. Very likely that this is not a CJS module."
|
|
44
|
-
)
|
|
45
|
-
magicString.append(
|
|
40
|
+
), magicString.append(
|
|
46
41
|
`;module.exports.__namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
|
|
47
42
|
);
|
|
48
43
|
}
|
|
49
|
-
}
|
|
50
44
|
return callback(null, magicString.toString(), map, meta);
|
|
51
|
-
} catch
|
|
45
|
+
} catch {
|
|
52
46
|
return callback(null, source, map, meta);
|
|
53
47
|
}
|
|
54
48
|
}
|
|
55
|
-
__name(loader, "loader");
|
|
56
49
|
export {
|
|
57
50
|
loader as default
|
|
58
51
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_igzmuwopv from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_igzmuwopv from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_igzmuwopv from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_igzmuwopv.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_igzmuwopv.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_igzmuwopv.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import "../_node-chunks/chunk-TOVLNAI6.js";
|
|
13
|
+
|
|
14
|
+
// src/loaders/storybook-mock-transform-loader.ts
|
|
15
|
+
import { rewriteSbMockImportCalls } from "storybook/internal/mocking-utils";
|
|
16
|
+
import { logger } from "storybook/internal/node-logger";
|
|
17
|
+
var storybookMockTransformLoader = function(source, sourceMap, meta) {
|
|
18
|
+
let callback = this.async();
|
|
19
|
+
try {
|
|
20
|
+
let result = rewriteSbMockImportCalls(source);
|
|
21
|
+
callback(null, result.code, result.map || void 0, meta);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
let filePath = this.resourcePath;
|
|
24
|
+
logger.debug(`Could not transform sb.mock(import(...)) calls in ${filePath}: ${error}`), callback(null, source, sourceMap, meta);
|
|
25
|
+
}
|
|
26
|
+
}, storybook_mock_transform_loader_default = storybookMockTransformLoader;
|
|
27
|
+
export {
|
|
28
|
+
storybook_mock_transform_loader_default as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_igzmuwopv from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_igzmuwopv from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_igzmuwopv from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_igzmuwopv.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_igzmuwopv.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_igzmuwopv.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import "../_node-chunks/chunk-TOVLNAI6.js";
|
|
13
|
+
|
|
14
|
+
// src/loaders/webpack-automock-loader.ts
|
|
15
|
+
import { babelParser, getAutomockCode } from "storybook/internal/mocking-utils";
|
|
16
|
+
function webpackAutomockLoader(source) {
|
|
17
|
+
let isSpy = this.getOptions().spy === "true";
|
|
18
|
+
return getAutomockCode(source, isSpy, babelParser).toString();
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
webpackAutomockLoader as default
|
|
22
|
+
};
|
|
@@ -1,61 +1,181 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_igzmuwopv from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_igzmuwopv from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_igzmuwopv from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_igzmuwopv.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_igzmuwopv.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_igzmuwopv.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
} from "../_node-chunks/chunk-
|
|
13
|
+
__require
|
|
14
|
+
} from "../_node-chunks/chunk-TOVLNAI6.js";
|
|
15
15
|
|
|
16
16
|
// src/presets/custom-webpack-preset.ts
|
|
17
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
18
|
+
import { findConfigFile } from "storybook/internal/common";
|
|
17
19
|
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
18
20
|
import { loadCustomWebpackConfig } from "@storybook/core-webpack";
|
|
19
21
|
import webpackModule from "webpack";
|
|
20
22
|
|
|
21
|
-
// src/
|
|
23
|
+
// src/plugins/webpack-inject-mocker-runtime-plugin.ts
|
|
24
|
+
import { getMockerRuntime } from "storybook/internal/mocking-utils";
|
|
25
|
+
var PLUGIN_NAME = "WebpackInjectMockerRuntimePlugin", WebpackInjectMockerRuntimePlugin = class {
|
|
26
|
+
// We need to lazy-require HtmlWebpackPlugin because it's an optional peer dependency.
|
|
27
|
+
getHtmlWebpackPlugin(compiler) {
|
|
28
|
+
try {
|
|
29
|
+
let constructor = compiler.options.plugins.find(
|
|
30
|
+
(p) => p?.constructor?.name === "HtmlWebpackPlugin"
|
|
31
|
+
)?.constructor;
|
|
32
|
+
return constructor || __require("html-webpack-plugin");
|
|
33
|
+
} catch {
|
|
34
|
+
return compiler.getInfrastructureLogger(PLUGIN_NAME).warn("html-webpack-plugin is not installed. Cannot inject mocker runtime."), null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The main entry point for the Webpack plugin.
|
|
39
|
+
*
|
|
40
|
+
* @param {Compiler} compiler The Webpack compiler instance.
|
|
41
|
+
*/
|
|
42
|
+
apply(compiler) {
|
|
43
|
+
let HtmlWebpackPlugin = this.getHtmlWebpackPlugin(compiler);
|
|
44
|
+
HtmlWebpackPlugin && compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
45
|
+
HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync(
|
|
46
|
+
PLUGIN_NAME,
|
|
47
|
+
(data, cb) => {
|
|
48
|
+
try {
|
|
49
|
+
let runtimeScriptContent = getMockerRuntime(), runtimeAssetName = "mocker-runtime-injected.js";
|
|
50
|
+
compilation.emitAsset(
|
|
51
|
+
runtimeAssetName,
|
|
52
|
+
new compiler.webpack.sources.RawSource(runtimeScriptContent)
|
|
53
|
+
), data.assets.js.unshift(runtimeAssetName), cb(null, data);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
cb(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/plugins/webpack-mock-plugin.ts
|
|
64
|
+
import { dirname, isAbsolute } from "node:path";
|
|
22
65
|
import { fileURLToPath } from "node:url";
|
|
66
|
+
import {
|
|
67
|
+
babelParser,
|
|
68
|
+
extractMockCalls,
|
|
69
|
+
getIsExternal,
|
|
70
|
+
resolveExternalModule,
|
|
71
|
+
resolveWithExtensions
|
|
72
|
+
} from "storybook/internal/mocking-utils";
|
|
73
|
+
import { findMockRedirect } from "@vitest/mocker/redirect";
|
|
74
|
+
var PLUGIN_NAME2 = "storybook-mock-plugin", WebpackMockPlugin = class {
|
|
75
|
+
constructor(options) {
|
|
76
|
+
this.mockMap = /* @__PURE__ */ new Map();
|
|
77
|
+
if (!options.previewConfigPath)
|
|
78
|
+
throw new Error(`[${PLUGIN_NAME2}] \`previewConfigPath\` is required.`);
|
|
79
|
+
this.options = options;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The main entry point for the Webpack plugin.
|
|
83
|
+
*
|
|
84
|
+
* @param {Compiler} compiler The Webpack compiler instance.
|
|
85
|
+
*/
|
|
86
|
+
apply(compiler) {
|
|
87
|
+
let logger3 = compiler.getInfrastructureLogger(PLUGIN_NAME2), updateMocks = () => {
|
|
88
|
+
this.mockMap = new Map(
|
|
89
|
+
this.extractAndResolveMocks(compiler).flatMap((mock) => [
|
|
90
|
+
// first one, full path
|
|
91
|
+
[mock.absolutePath, mock],
|
|
92
|
+
// second one, without the extension
|
|
93
|
+
[mock.absolutePath.replace(/\.[^.]+$/, ""), mock]
|
|
94
|
+
])
|
|
95
|
+
), logger3.info(`Mock map updated with ${this.mockMap.size / 2} mocks.`);
|
|
96
|
+
};
|
|
97
|
+
compiler.hooks.beforeRun.tap(PLUGIN_NAME2, updateMocks), compiler.hooks.watchRun.tap(PLUGIN_NAME2, updateMocks), new compiler.webpack.NormalModuleReplacementPlugin(/.*/, (resource) => {
|
|
98
|
+
try {
|
|
99
|
+
let path = resource.request, importer = resource.context, absolutePath = getIsExternal(path, importer) ? resolveExternalModule(path, importer) : resolveWithExtensions(path, importer);
|
|
100
|
+
this.mockMap.has(absolutePath) && (resource.request = this.mockMap.get(absolutePath).replacementResource);
|
|
101
|
+
} catch {
|
|
102
|
+
logger3.debug(`Could not resolve mock for "${resource.request}".`);
|
|
103
|
+
}
|
|
104
|
+
}).apply(compiler), compiler.hooks.afterCompile.tap(PLUGIN_NAME2, (compilation) => {
|
|
105
|
+
compilation.fileDependencies.add(this.options.previewConfigPath);
|
|
106
|
+
for (let mock of this.mockMap.values())
|
|
107
|
+
isAbsolute(mock.replacementResource) && mock.replacementResource.includes("__mocks__") && compilation.contextDependencies.add(dirname(mock.replacementResource));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reads the preview config, parses it to find all `sb.mock()` calls, and resolves their
|
|
112
|
+
* corresponding mock implementations.
|
|
113
|
+
*
|
|
114
|
+
* @param {Compiler} compiler The Webpack compiler instance.
|
|
115
|
+
* @returns {ResolvedMock[]} An array of fully processed mocks.
|
|
116
|
+
*/
|
|
117
|
+
extractAndResolveMocks(compiler) {
|
|
118
|
+
let { previewConfigPath } = this.options, logger3 = compiler.getInfrastructureLogger(PLUGIN_NAME2), mocks = extractMockCalls(
|
|
119
|
+
{ previewConfigPath, configDir: dirname(previewConfigPath) },
|
|
120
|
+
babelParser,
|
|
121
|
+
compiler.context,
|
|
122
|
+
findMockRedirect
|
|
123
|
+
), resolvedMocks = [];
|
|
124
|
+
for (let mock of mocks)
|
|
125
|
+
try {
|
|
126
|
+
let { absolutePath, redirectPath } = mock, replacementResource;
|
|
127
|
+
redirectPath ? replacementResource = redirectPath : replacementResource = `${fileURLToPath(
|
|
128
|
+
import.meta.resolve("@storybook/builder-webpack5/loaders/webpack-automock-loader")
|
|
129
|
+
)}?spy=${mock.spy}!${absolutePath}`, resolvedMocks.push({
|
|
130
|
+
...mock,
|
|
131
|
+
replacementResource
|
|
132
|
+
});
|
|
133
|
+
} catch {
|
|
134
|
+
logger3.warn(`Could not resolve mock for "${mock.path}". It will be ignored.`);
|
|
135
|
+
}
|
|
136
|
+
return resolvedMocks;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/preview/base-webpack.config.ts
|
|
141
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
23
142
|
import { logger } from "storybook/internal/node-logger";
|
|
24
143
|
async function createDefaultWebpackConfig(storybookBaseConfig, options) {
|
|
25
144
|
if (options.presetsList?.some(
|
|
26
145
|
(preset) => /@storybook(\/|\\)preset-create-react-app/.test(
|
|
27
|
-
typeof preset
|
|
146
|
+
typeof preset == "string" ? preset : preset.name
|
|
28
147
|
)
|
|
29
|
-
))
|
|
148
|
+
))
|
|
30
149
|
return storybookBaseConfig;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
loader: fileURLToPath(import.meta.resolve("css-loader")),
|
|
49
|
-
options: {
|
|
50
|
-
importLoaders: 1
|
|
51
|
-
}
|
|
150
|
+
let hasPostcssAddon = options.presetsList?.some(
|
|
151
|
+
(preset) => /@storybook(\/|\\)addon-postcss/.test(typeof preset == "string" ? preset : preset.name)
|
|
152
|
+
), cssLoaders = {};
|
|
153
|
+
hasPostcssAddon || (logger.info("Using implicit CSS loaders"), cssLoaders = {
|
|
154
|
+
test: /\.css$/,
|
|
155
|
+
sideEffects: !0,
|
|
156
|
+
use: [
|
|
157
|
+
// TODO: Decide if we want to keep style-loader & css-loader in core
|
|
158
|
+
// Trying to apply style-loader or css-loader to files that already have been
|
|
159
|
+
// processed by them causes webpack to crash, so no one else can add similar
|
|
160
|
+
// loader configurations to the `.css` extension.
|
|
161
|
+
fileURLToPath2(import.meta.resolve("style-loader")),
|
|
162
|
+
{
|
|
163
|
+
loader: fileURLToPath2(import.meta.resolve("css-loader")),
|
|
164
|
+
options: {
|
|
165
|
+
importLoaders: 1
|
|
52
166
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
});
|
|
170
|
+
let isProd = storybookBaseConfig.mode !== "development";
|
|
57
171
|
return {
|
|
58
172
|
...storybookBaseConfig,
|
|
173
|
+
// TODO: Implement the clearing functionality of StyledConsoleLogger so that we can use it for webpack
|
|
174
|
+
// The issue currently is that the status line is not cleared when the webpack compiler is run,
|
|
175
|
+
// which causes the status line to be printed multiple times.
|
|
176
|
+
// infrastructureLogging: {
|
|
177
|
+
// console: new StyledConsoleLogger({ prefix: 'Webpack', color: 'bgBlue' }),
|
|
178
|
+
// },
|
|
59
179
|
module: {
|
|
60
180
|
...storybookBaseConfig.module,
|
|
61
181
|
rules: [
|
|
@@ -100,55 +220,54 @@ async function createDefaultWebpackConfig(storybookBaseConfig, options) {
|
|
|
100
220
|
"..."
|
|
101
221
|
],
|
|
102
222
|
fallback: {
|
|
103
|
-
crypto:
|
|
104
|
-
assert:
|
|
223
|
+
crypto: !1,
|
|
224
|
+
assert: !1,
|
|
105
225
|
...storybookBaseConfig.resolve?.fallback
|
|
106
226
|
}
|
|
107
227
|
}
|
|
108
228
|
};
|
|
109
229
|
}
|
|
110
|
-
__name(createDefaultWebpackConfig, "createDefaultWebpackConfig");
|
|
111
230
|
|
|
112
231
|
// src/presets/custom-webpack-preset.ts
|
|
113
|
-
var swc =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
env
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
bugfixes: config?.env?.bugfixes ?? true
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
}, "swc");
|
|
130
|
-
async function webpack(config, options) {
|
|
131
|
-
const { configDir, configType, presets } = options;
|
|
132
|
-
const coreOptions = await presets.apply("core");
|
|
133
|
-
let defaultConfig = config;
|
|
134
|
-
if (!coreOptions?.disableWebpackDefaults) {
|
|
135
|
-
defaultConfig = await createDefaultWebpackConfig(config, options);
|
|
136
|
-
}
|
|
137
|
-
const finalDefaultConfig = await presets.apply("webpackFinal", defaultConfig, options);
|
|
138
|
-
const customConfig = await loadCustomWebpackConfig(configDir);
|
|
139
|
-
if (typeof customConfig === "function") {
|
|
140
|
-
logger2.info("=> Loading custom Webpack config (full-control mode).");
|
|
141
|
-
return customConfig({ config: finalDefaultConfig, mode: configType });
|
|
232
|
+
var swc = (config) => ({
|
|
233
|
+
...config,
|
|
234
|
+
env: {
|
|
235
|
+
...config?.env ?? {},
|
|
236
|
+
targets: config?.env?.targets ?? {
|
|
237
|
+
chrome: 100,
|
|
238
|
+
safari: 15,
|
|
239
|
+
firefox: 91
|
|
240
|
+
},
|
|
241
|
+
// Transpiles the broken syntax to the closest non-broken modern syntax.
|
|
242
|
+
// E.g. it won't transpile parameter destructuring in Safari
|
|
243
|
+
// which would break how we detect if the mount context property is used in the play function.
|
|
244
|
+
bugfixes: config?.env?.bugfixes ?? !0
|
|
142
245
|
}
|
|
143
|
-
|
|
144
|
-
|
|
246
|
+
});
|
|
247
|
+
async function webpackFinal(config, options) {
|
|
248
|
+
let previewConfigPath = findConfigFile("preview", options.configDir);
|
|
249
|
+
return previewConfigPath && (config.plugins = config.plugins || [], config.module.rules.push({
|
|
250
|
+
test: /preview\.(t|j)sx?$/,
|
|
251
|
+
use: [
|
|
252
|
+
{
|
|
253
|
+
loader: fileURLToPath3(
|
|
254
|
+
import.meta.resolve("@storybook/builder-webpack5/loaders/storybook-mock-transform-loader")
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
]
|
|
258
|
+
}), config.plugins.push(new WebpackMockPlugin({ previewConfigPath })), config.plugins.push(new WebpackInjectMockerRuntimePlugin())), config;
|
|
259
|
+
}
|
|
260
|
+
async function webpack(config, options) {
|
|
261
|
+
let { configDir, configType, presets } = options, coreOptions = await presets.apply("core"), defaultConfig = config;
|
|
262
|
+
coreOptions?.disableWebpackDefaults || (defaultConfig = await createDefaultWebpackConfig(config, options));
|
|
263
|
+
let finalDefaultConfig = await presets.apply("webpackFinal", defaultConfig, options), customConfig = await loadCustomWebpackConfig(configDir);
|
|
264
|
+
return typeof customConfig == "function" ? (logger2.info("Loading custom Webpack config (full-control mode)."), customConfig({ config: finalDefaultConfig, mode: configType })) : (logger2.info("Using default Webpack5 setup"), finalDefaultConfig);
|
|
145
265
|
}
|
|
146
|
-
|
|
147
|
-
var webpackInstance = /* @__PURE__ */ __name(async () => webpackModule, "webpackInstance");
|
|
148
|
-
var webpackVersion = /* @__PURE__ */ __name(async () => "5", "webpackVersion");
|
|
266
|
+
var webpackInstance = async () => webpackModule, webpackVersion = async () => "5";
|
|
149
267
|
export {
|
|
150
268
|
swc,
|
|
151
269
|
webpack,
|
|
270
|
+
webpackFinal,
|
|
152
271
|
webpackInstance,
|
|
153
272
|
webpackVersion
|
|
154
273
|
};
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_igzmuwopv from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_igzmuwopv from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_igzmuwopv from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_igzmuwopv.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_igzmuwopv.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_igzmuwopv.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
13
|
getVirtualModules
|
|
14
|
-
} from "../_node-chunks/chunk-
|
|
15
|
-
import
|
|
16
|
-
__name
|
|
17
|
-
} from "../_node-chunks/chunk-VEIR4MFH.js";
|
|
14
|
+
} from "../_node-chunks/chunk-CAP7MRPN.js";
|
|
15
|
+
import "../_node-chunks/chunk-TOVLNAI6.js";
|
|
18
16
|
|
|
19
17
|
// src/presets/preview-preset.ts
|
|
20
18
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -36,9 +34,8 @@ import TerserWebpackPlugin from "terser-webpack-plugin";
|
|
|
36
34
|
import { dedent } from "ts-dedent";
|
|
37
35
|
import webpackModule from "webpack";
|
|
38
36
|
import VirtualModulePlugin from "webpack-virtual-modules";
|
|
39
|
-
var { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin } = webpackModule
|
|
40
|
-
|
|
41
|
-
const {
|
|
37
|
+
var { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin } = webpackModule, iframe_webpack_config_default = async (options) => {
|
|
38
|
+
let {
|
|
42
39
|
outputDir = join(".", "public"),
|
|
43
40
|
quiet,
|
|
44
41
|
packageJson,
|
|
@@ -47,10 +44,7 @@ var iframe_webpack_config_default = /* @__PURE__ */ __name(async (options) => {
|
|
|
47
44
|
previewUrl,
|
|
48
45
|
typescriptOptions,
|
|
49
46
|
features
|
|
50
|
-
} = options
|
|
51
|
-
const isProd = configType === "PRODUCTION";
|
|
52
|
-
const workingDir = process.cwd();
|
|
53
|
-
const [
|
|
47
|
+
} = options, isProd = configType === "PRODUCTION", workingDir = process.cwd(), [
|
|
54
48
|
coreOptions,
|
|
55
49
|
frameworkOptions,
|
|
56
50
|
envs,
|
|
@@ -78,36 +72,27 @@ var iframe_webpack_config_default = /* @__PURE__ */ __name(async (options) => {
|
|
|
78
72
|
options.cache?.get("modulesCount", 1e3),
|
|
79
73
|
options.presets.apply("build"),
|
|
80
74
|
presets.apply("tags", {})
|
|
81
|
-
])
|
|
82
|
-
const stories = normalizeStories(nonNormalizedStories, {
|
|
75
|
+
]), stories = normalizeStories(nonNormalizedStories, {
|
|
83
76
|
configDir: options.configDir,
|
|
84
77
|
workingDir
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler;
|
|
88
|
-
const tsCheckOptions = typescriptOptions.checkOptions || {};
|
|
89
|
-
const cacheConfig = builderOptions.fsCache ? { cache: { type: "filesystem" } } : {};
|
|
90
|
-
const lazyCompilationConfig = builderOptions.lazyCompilation && !isProd ? {
|
|
91
|
-
lazyCompilation: { entries: false }
|
|
78
|
+
}), builderOptions = await getBuilderOptions(options), shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler, tsCheckOptions = typescriptOptions.checkOptions || {}, cacheConfig = builderOptions.fsCache ? { cache: { type: "filesystem" } } : {}, lazyCompilationConfig = builderOptions.lazyCompilation && !isProd ? {
|
|
79
|
+
lazyCompilation: { entries: !1 }
|
|
92
80
|
} : {};
|
|
93
|
-
if (!template)
|
|
81
|
+
if (!template)
|
|
94
82
|
throw new Error(dedent`
|
|
95
83
|
Storybook's Webpack5 builder requires a template to be specified.
|
|
96
84
|
Somehow you've ended up with a falsy value for the template option.
|
|
97
85
|
|
|
98
86
|
Please file an issue at https://github.com/storybookjs/storybook with a reproduction.
|
|
99
87
|
`);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
externals["@storybook/addon-docs/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__";
|
|
104
|
-
}
|
|
105
|
-
const { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(options);
|
|
88
|
+
let externals = globalsNameReferenceMap;
|
|
89
|
+
build?.test?.disableBlocks && (externals["@storybook/addon-docs/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__");
|
|
90
|
+
let { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(options);
|
|
106
91
|
return {
|
|
107
92
|
name: "preview",
|
|
108
93
|
mode: isProd ? "production" : "development",
|
|
109
94
|
bail: isProd,
|
|
110
|
-
devtool: options.build?.test?.disableSourcemaps ?
|
|
95
|
+
devtool: options.build?.test?.disableSourcemaps ? !1 : "cheap-module-source-map",
|
|
111
96
|
entry: [...entries2 ?? [], ...dynamicEntries],
|
|
112
97
|
output: {
|
|
113
98
|
path: resolve(process.cwd(), outputDir),
|
|
@@ -133,11 +118,11 @@ var iframe_webpack_config_default = /* @__PURE__ */ __name(async (options) => {
|
|
|
133
118
|
plugins: [
|
|
134
119
|
Object.keys(virtualModuleMapping).length > 0 ? new VirtualModulePlugin(virtualModuleMapping) : null,
|
|
135
120
|
new HtmlWebpackPlugin({
|
|
136
|
-
filename:
|
|
121
|
+
filename: "iframe.html",
|
|
137
122
|
// FIXME: `none` isn't a known option
|
|
138
123
|
chunksSortMode: "none",
|
|
139
|
-
alwaysWriteToDisk:
|
|
140
|
-
inject:
|
|
124
|
+
alwaysWriteToDisk: !0,
|
|
125
|
+
inject: !1,
|
|
141
126
|
template,
|
|
142
127
|
templateParameters: {
|
|
143
128
|
version: packageJson?.version,
|
|
@@ -160,12 +145,12 @@ var iframe_webpack_config_default = /* @__PURE__ */ __name(async (options) => {
|
|
|
160
145
|
bodyHtmlSnippet
|
|
161
146
|
},
|
|
162
147
|
minify: {
|
|
163
|
-
collapseWhitespace:
|
|
164
|
-
removeComments:
|
|
165
|
-
removeRedundantAttributes:
|
|
166
|
-
removeScriptTypeAttributes:
|
|
167
|
-
removeStyleLinkTypeAttributes:
|
|
168
|
-
useShortDoctype:
|
|
148
|
+
collapseWhitespace: !0,
|
|
149
|
+
removeComments: !0,
|
|
150
|
+
removeRedundantAttributes: !0,
|
|
151
|
+
removeScriptTypeAttributes: !1,
|
|
152
|
+
removeStyleLinkTypeAttributes: !0,
|
|
153
|
+
useShortDoctype: !0
|
|
169
154
|
}
|
|
170
155
|
}),
|
|
171
156
|
new DefinePlugin({
|
|
@@ -181,7 +166,7 @@ var iframe_webpack_config_default = /* @__PURE__ */ __name(async (options) => {
|
|
|
181
166
|
].filter(Boolean),
|
|
182
167
|
module: {
|
|
183
168
|
// Disable warning for dynamic requires
|
|
184
|
-
unknownContextCritical:
|
|
169
|
+
unknownContextCritical: !1,
|
|
185
170
|
rules: [
|
|
186
171
|
{
|
|
187
172
|
test: /\.stories\.([tj])sx?$|(stories|story)\.mdx$/,
|
|
@@ -202,7 +187,7 @@ var iframe_webpack_config_default = /* @__PURE__ */ __name(async (options) => {
|
|
|
202
187
|
{
|
|
203
188
|
test: /\.m?js$/,
|
|
204
189
|
resolve: {
|
|
205
|
-
fullySpecified:
|
|
190
|
+
fullySpecified: !1
|
|
206
191
|
}
|
|
207
192
|
},
|
|
208
193
|
{
|
|
@@ -223,15 +208,15 @@ var iframe_webpack_config_default = /* @__PURE__ */ __name(async (options) => {
|
|
|
223
208
|
splitChunks: {
|
|
224
209
|
chunks: "all"
|
|
225
210
|
},
|
|
226
|
-
runtimeChunk:
|
|
227
|
-
sideEffects:
|
|
228
|
-
usedExports: options.build?.test?.disableTreeShaking ?
|
|
211
|
+
runtimeChunk: !0,
|
|
212
|
+
sideEffects: !0,
|
|
213
|
+
usedExports: options.build?.test?.disableTreeShaking ? !1 : isProd,
|
|
229
214
|
moduleIds: "named",
|
|
230
215
|
...isProd ? {
|
|
231
|
-
minimize:
|
|
216
|
+
minimize: !0,
|
|
232
217
|
minimizer: options.build?.test?.esbuildMinify ? [
|
|
233
218
|
new TerserWebpackPlugin({
|
|
234
|
-
parallel:
|
|
219
|
+
parallel: !0,
|
|
235
220
|
minify: TerserWebpackPlugin.esbuildMinify,
|
|
236
221
|
terserOptions: {
|
|
237
222
|
sourcemap: !options.build?.test?.disableSourcemaps,
|
|
@@ -240,42 +225,37 @@ var iframe_webpack_config_default = /* @__PURE__ */ __name(async (options) => {
|
|
|
240
225
|
})
|
|
241
226
|
] : [
|
|
242
227
|
new TerserWebpackPlugin({
|
|
243
|
-
parallel:
|
|
228
|
+
parallel: !0,
|
|
244
229
|
terserOptions: {
|
|
245
230
|
sourceMap: !options.build?.test?.disableSourcemaps,
|
|
246
|
-
mangle:
|
|
247
|
-
keep_fnames:
|
|
231
|
+
mangle: !1,
|
|
232
|
+
keep_fnames: !0
|
|
248
233
|
}
|
|
249
234
|
})
|
|
250
235
|
]
|
|
251
236
|
} : {}
|
|
252
237
|
},
|
|
253
238
|
performance: {
|
|
254
|
-
hints: isProd ? "warning" :
|
|
239
|
+
hints: isProd ? "warning" : !1
|
|
255
240
|
},
|
|
256
241
|
...cacheConfig,
|
|
257
242
|
experiments: { ...lazyCompilationConfig }
|
|
258
243
|
};
|
|
259
|
-
}
|
|
244
|
+
};
|
|
260
245
|
|
|
261
246
|
// src/presets/preview-preset.ts
|
|
262
|
-
var webpack =
|
|
263
|
-
var entries = /* @__PURE__ */ __name(async (_, options) => {
|
|
247
|
+
var webpack = async (_, options) => iframe_webpack_config_default(options), entries = async (_, options) => {
|
|
264
248
|
let result = [];
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
return result;
|
|
277
|
-
}, "entries");
|
|
278
|
-
var previewMainTemplate = /* @__PURE__ */ __name(() => fileURLToPath2(import.meta.resolve("@storybook/builder-webpack5/templates/preview.ejs")), "previewMainTemplate");
|
|
249
|
+
return options.configType === "DEVELOPMENT" && (result = result.concat(
|
|
250
|
+
`${fileURLToPath2(
|
|
251
|
+
import.meta.resolve("webpack-hot-middleware/client.js")
|
|
252
|
+
)}?reload=true&quiet=false&overlay=${JSON.stringify({
|
|
253
|
+
errors: !0,
|
|
254
|
+
warnings: !1,
|
|
255
|
+
runtimeErrors: !1
|
|
256
|
+
})}&noInfo=${options.quiet}`
|
|
257
|
+
)), result;
|
|
258
|
+
}, previewMainTemplate = () => fileURLToPath2(import.meta.resolve("@storybook/builder-webpack5/templates/preview.ejs"));
|
|
279
259
|
export {
|
|
280
260
|
entries,
|
|
281
261
|
previewMainTemplate,
|