mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 05:21:48 +08:00
Merge pull request #5523 from storybooks/core/ignore-preview-bundle
Core - Allow ignoring preview bundle building in core
This commit is contained in:
commit
1dfb31f9b3
@ -3,4 +3,12 @@ const serverUtils = require('./dist/server/utils/template');
|
||||
const buildStatic = require('./dist/server/build-static');
|
||||
const buildDev = require('./dist/server/build-dev');
|
||||
|
||||
module.exports = Object.assign({}, defaultWebpackConfig, buildStatic, buildDev, serverUtils);
|
||||
const managerPreset = require.resolve('./dist/server/manager/manager-preset');
|
||||
|
||||
module.exports = Object.assign(
|
||||
{ managerPreset },
|
||||
defaultWebpackConfig,
|
||||
buildStatic,
|
||||
buildDev,
|
||||
serverUtils
|
||||
);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import express from 'express';
|
||||
import https from 'https';
|
||||
import http from 'http';
|
||||
import ip from 'ip';
|
||||
import favicon from 'serve-favicon';
|
||||
import path from 'path';
|
||||
@ -36,7 +37,7 @@ const writeStats = async (name, stats) => {
|
||||
|
||||
async function getServer(app, options) {
|
||||
if (!options.https) {
|
||||
return app;
|
||||
return http.createServer(app);
|
||||
}
|
||||
|
||||
if (!options.sslCert) {
|
||||
@ -199,15 +200,18 @@ function outputStartupInformation(options) {
|
||||
['On your network:', chalk.cyan(networkAddress)]
|
||||
);
|
||||
|
||||
const timeStatement = previewTotalTime
|
||||
? `${chalk.underline(prettyTime(managerTotalTime))} for manager and ${chalk.underline(
|
||||
prettyTime(previewTotalTime)
|
||||
)} for preview`
|
||||
: `${chalk.underline(prettyTime(managerTotalTime))}`;
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
boxen(
|
||||
stripIndents`
|
||||
${colors.green(`Storybook ${chalk.bold(version)} started`)}
|
||||
${chalk.gray(stripIndents`
|
||||
${chalk.underline(prettyTime(managerTotalTime))} for manager and ${chalk.underline(
|
||||
prettyTime(previewTotalTime)
|
||||
)} for preview`)}
|
||||
${chalk.gray(timeStatement)}
|
||||
|
||||
${serveMessage.toString()}${updateMessage ? `\n\n${updateMessage}` : ''}
|
||||
`,
|
||||
@ -217,7 +221,7 @@ function outputStartupInformation(options) {
|
||||
}
|
||||
|
||||
async function outputStats(previewStats, managerStats) {
|
||||
await writeStats('preview', previewStats);
|
||||
if (previewStats) await writeStats('preview', previewStats);
|
||||
await writeStats('manager', managerStats);
|
||||
logger.info(`stats written to => ${chalk.cyan(path.join(cacheDir, '[name].json'))}`);
|
||||
}
|
||||
@ -234,7 +238,7 @@ function openInBrowser(address) {
|
||||
|
||||
export async function buildDevStandalone(options) {
|
||||
try {
|
||||
const { port, host } = options;
|
||||
const { port, host, extendServer } = options;
|
||||
|
||||
// Used with `app.listen` below
|
||||
const listenAddr = [port];
|
||||
@ -246,6 +250,10 @@ export async function buildDevStandalone(options) {
|
||||
const app = express();
|
||||
const server = await getServer(app, options);
|
||||
|
||||
if (typeof extendServer === 'function') {
|
||||
extendServer(server);
|
||||
}
|
||||
|
||||
await applyStatic(app, options);
|
||||
|
||||
const {
|
||||
@ -279,8 +287,15 @@ export async function buildDevStandalone(options) {
|
||||
if (options.smokeTest) {
|
||||
await outputStats(previewStats, managerStats);
|
||||
|
||||
process.exit(previewStats.toJson().warnings.length ? 1 : 0);
|
||||
process.exit(managerStats.toJson().warnings.length ? 1 : 0);
|
||||
let warning = 0;
|
||||
|
||||
if (!options.ignorePreview) {
|
||||
warning += previewStats.toJson().warnings.length;
|
||||
}
|
||||
|
||||
warning += managerStats.toJson().warnings.length;
|
||||
|
||||
process.exit(warning ? 1 : 0);
|
||||
} else if (!options.ci) {
|
||||
openInBrowser(address);
|
||||
}
|
||||
|
@ -71,63 +71,66 @@ export default function(options) {
|
||||
})
|
||||
);
|
||||
|
||||
const previewPromise = loadConfig({
|
||||
configType,
|
||||
outputDir,
|
||||
cache,
|
||||
corePresets: [require.resolve('./preview/preview-preset.js')],
|
||||
overridePresets: [require.resolve('./preview/custom-webpack-preset.js')],
|
||||
...options,
|
||||
}).then(previewConfig => {
|
||||
const middlewareFn = getMiddleware(configDir);
|
||||
|
||||
// remove the leading '/'
|
||||
let { publicPath } = previewConfig.output;
|
||||
if (publicPath[0] === '/') {
|
||||
publicPath = publicPath.slice(1);
|
||||
}
|
||||
|
||||
const previewCompiler = webpack(previewConfig);
|
||||
const devMiddlewareOptions = {
|
||||
publicPath: previewConfig.output.publicPath,
|
||||
watchOptions: {
|
||||
aggregateTimeout: 1,
|
||||
ignored: /node_modules/,
|
||||
...(previewConfig.watchOptions || {}),
|
||||
},
|
||||
// this actually causes 0 (regular) output from wdm & webpack
|
||||
logLevel: 'warn',
|
||||
clientLogLevel: 'warning',
|
||||
noInfo: true,
|
||||
...previewConfig.devServer,
|
||||
};
|
||||
|
||||
const webpackDevMiddlewareInstance = webpackDevMiddleware(
|
||||
previewCompiler,
|
||||
devMiddlewareOptions
|
||||
);
|
||||
router.use(webpackDevMiddlewareInstance);
|
||||
router.use(webpackHotMiddleware(previewCompiler));
|
||||
|
||||
// custom middleware
|
||||
middlewareFn(router);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
previewReject = reject;
|
||||
webpackDevMiddlewareInstance.waitUntilValid(stats => {
|
||||
previewTotalTime = process.hrtime(startTime);
|
||||
|
||||
if (!stats) {
|
||||
reject(new Error('no stats after building preview'));
|
||||
} else if (stats.hasErrors()) {
|
||||
reject(stats);
|
||||
} else {
|
||||
resolve(stats);
|
||||
const previewPromise = options.ignorePreview
|
||||
? new Promise(resolve => resolve())
|
||||
: loadConfig({
|
||||
configType,
|
||||
outputDir,
|
||||
cache,
|
||||
corePresets: [require.resolve('./preview/preview-preset.js')],
|
||||
overridePresets: [require.resolve('./preview/custom-webpack-preset.js')],
|
||||
...options,
|
||||
}).then(previewConfig => {
|
||||
// remove the leading '/'
|
||||
let { publicPath } = previewConfig.output;
|
||||
if (publicPath[0] === '/') {
|
||||
publicPath = publicPath.slice(1);
|
||||
}
|
||||
|
||||
const previewCompiler = webpack(previewConfig);
|
||||
|
||||
const devMiddlewareOptions = {
|
||||
publicPath: previewConfig.output.publicPath,
|
||||
watchOptions: {
|
||||
aggregateTimeout: 1,
|
||||
ignored: /node_modules/,
|
||||
...(previewConfig.watchOptions || {}),
|
||||
},
|
||||
// this actually causes 0 (regular) output from wdm & webpack
|
||||
logLevel: 'warn',
|
||||
clientLogLevel: 'warning',
|
||||
noInfo: true,
|
||||
...previewConfig.devServer,
|
||||
};
|
||||
|
||||
const webpackDevMiddlewareInstance = webpackDevMiddleware(
|
||||
previewCompiler,
|
||||
devMiddlewareOptions
|
||||
);
|
||||
|
||||
router.use(webpackDevMiddlewareInstance);
|
||||
router.use(webpackHotMiddleware(previewCompiler));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
previewReject = reject;
|
||||
webpackDevMiddlewareInstance.waitUntilValid(stats => {
|
||||
previewTotalTime = process.hrtime(startTime);
|
||||
|
||||
if (!stats) {
|
||||
reject(new Error('no stats after building preview'));
|
||||
} else if (stats.hasErrors()) {
|
||||
reject(stats);
|
||||
} else {
|
||||
resolve(stats);
|
||||
}
|
||||
});
|
||||
previewProcess = webpackDevMiddlewareInstance;
|
||||
});
|
||||
});
|
||||
previewProcess = webpackDevMiddlewareInstance;
|
||||
});
|
||||
});
|
||||
|
||||
// custom middleware
|
||||
const middlewareFn = getMiddleware(configDir);
|
||||
middlewareFn(router);
|
||||
|
||||
return Promise.all([managerPromise, previewPromise]).then(([managerStats, previewStats]) => {
|
||||
resolved = true;
|
||||
|
@ -6,7 +6,7 @@ export async function managerWebpack(_, options) {
|
||||
}
|
||||
|
||||
export async function managerEntries(_, options) {
|
||||
const { presets } = options;
|
||||
const { presets, managerEntry = '../../client/manager' } = options;
|
||||
const entries = [require.resolve('../common/polyfills')];
|
||||
|
||||
const installedAddons = await presets.apply('addons', [], options);
|
||||
@ -15,7 +15,7 @@ export async function managerEntries(_, options) {
|
||||
entries.push(...installedAddons);
|
||||
}
|
||||
|
||||
entries.push(require.resolve('../../client/manager'));
|
||||
entries.push(require.resolve(managerEntry));
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user