Skip to content
This repository was archived by the owner on Nov 10, 2017. It is now read-only.

Commit 084d3ec

Browse files
committed
Added environment option.
1 parent 8354687 commit 084d3ec

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/bin/storybook-start.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ program
1010
.option('-p, --port <port>', 'port to listen on')
1111
.option('-s, --secured', 'whether server is running on https')
1212
.option('-c, --config-dir [dir-name]', 'storybook config directory')
13+
.option('-e, --environment [environment]', 'DEVELOPMENT/PRODUCTION environment for webpack')
1314
.option('-r, --reset-cache', 'reset react native packager')
1415
.option('--skip-packager', 'run only storybook server')
1516
.option('-i, --manual-id', 'allow multiple users to work with same storybook')
@@ -22,7 +23,14 @@ if (program.host) {
2223
listenAddr.push(program.host);
2324
}
2425

25-
const server = new Server({projectDir, configDir, manualId: program.manualId, secured: program.secured});
26+
const server = new Server({
27+
projectDir,
28+
configDir,
29+
environment: program.environment,
30+
manualId: program.manualId,
31+
secured: program.secured
32+
});
33+
2634
server.listen(...listenAddr, function (err) {
2735
if (err) {
2836
throw err;

src/server/config/webpack.config.prod.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ const config = {
1414
devtool: '#cheap-module-source-map',
1515
entry: entries,
1616
output: {
17+
path: path.join(__dirname, 'dist'),
1718
filename: 'static/[name].bundle.js',
1819
// Here we set the publicPath to ''.
1920
// This allows us to deploy storybook into subpaths like GitHub pages.
2021
// This works with css and image loaders too.
2122
// This is working for storybook since, we don't use pushState urls and
2223
// relative URLs works always.
23-
publicPath: '',
24+
publicPath: '/',
2425
},
2526
plugins: [
2627
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),

src/server/middleware.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import webpack from 'webpack';
55
import webpackDevMiddleware from 'webpack-dev-middleware';
66
import webpackHotMiddleware from 'webpack-hot-middleware';
77
import baseConfig from './config/webpack.config';
8+
import baseProductionConfig from './config/webpack.config.prod';
89
import loadConfig from './config';
910
import getIndexHtml from './index.html';
1011

@@ -23,7 +24,9 @@ function getMiddleware(configDir) {
2324
export default function ({projectDir, configDir, ...options}) {
2425
// Build the webpack configuration using the `baseConfig`
2526
// custom `.babelrc` file and `webpack.config.js` files
26-
const config = loadConfig('DEVELOPMENT', baseConfig, projectDir, configDir);
27+
const environment = options.environment || 'DEVELOPMENT';
28+
const currentWebpackConfig = environment === 'PRODUCTION' ? baseProductionConfig : baseConfig;
29+
const config = loadConfig(environment, currentWebpackConfig, projectDir, configDir);
2730

2831
// remove the leading '/'
2932
let publicPath = config.output.publicPath;

0 commit comments

Comments
 (0)