-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass default webpack config as third argument in Full Control Mode #2796
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import deprecate from 'util-deprecate'; | ||
import { createDefaultWebpackConfig } from '@storybook/core/server'; | ||
import { includePaths } from '../utils'; | ||
|
||
module.exports = storybookBaseConfig => | ||
createDefaultWebpackConfig(storybookBaseConfig, includePaths); | ||
module.exports = deprecate( | ||
createDefaultWebpackConfig, | ||
"importing default webpack config generator from '@storybook/angular/dist/server/config/defaults/webpack.config.js' is deprecated. Use third argument of your exported function instead. See https://storybook.js.org/configurations/custom-webpack-config/#full-control-mode--default" | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import deprecate from 'util-deprecate'; | ||
import { createDefaultWebpackConfig } from '@storybook/core/server'; | ||
import { includePaths } from '../utils'; | ||
|
||
module.exports = storybookBaseConfig => | ||
createDefaultWebpackConfig(storybookBaseConfig, includePaths); | ||
module.exports = deprecate( | ||
createDefaultWebpackConfig, | ||
"importing default webpack config generator from '@storybook/polymer/dist/server/config/defaults/webpack.config.js' is deprecated. Use third argument of your exported function instead. See https://storybook.js.org/configurations/custom-webpack-config/#full-control-mode--default" | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,7 @@ | ||
import autoprefixer from 'autoprefixer'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I checked this config before, it was a bit different from the default config of the other apps. Are those differences minor? For example, is it safe to change "loaders" to "rules"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Generally, the differences are there because changes to configs in react and vue weren't applied here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we need to factor our the RN manager config into |
||
import { includePaths } from '../utils'; | ||
import deprecate from 'util-deprecate'; | ||
import { createDefaultWebpackConfig } from '@storybook/core/server'; | ||
|
||
// Add a default custom config which is similar to what React Create App does. | ||
module.exports = storybookBaseConfig => { | ||
const newConfig = { ...storybookBaseConfig }; | ||
|
||
newConfig.module.loaders = [ | ||
...newConfig.module.loaders, | ||
{ | ||
test: /\.css?$/, | ||
include: includePaths, | ||
use: [ | ||
require.resolve('style-loader'), | ||
require.resolve('css-loader'), | ||
{ | ||
loader: require.resolve('postcss-loader'), | ||
options: { | ||
plugins: () => [ | ||
autoprefixer({ | ||
browsers: ['>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 9'], | ||
}), | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
test: /\.json$/, | ||
include: includePaths, | ||
loader: require.resolve('json-loader'), | ||
}, | ||
{ | ||
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/, | ||
include: includePaths, | ||
loader: require.resolve('file-loader'), | ||
query: { | ||
name: 'static/media/[name].[hash:8].[ext]', | ||
}, | ||
}, | ||
{ | ||
test: /\.(mp4|webm)(\?.*)?$/, | ||
include: includePaths, | ||
loader: require.resolve('url-loader'), | ||
query: { | ||
limit: 10000, | ||
name: 'static/media/[name].[hash:8].[ext]', | ||
}, | ||
}, | ||
]; | ||
|
||
newConfig.resolve = { | ||
...newConfig.resolve, | ||
alias: { | ||
...((newConfig.resolve && newConfig.resolve.alias) || {}), | ||
// This is to support NPM2 | ||
'babel-runtime/regenerator': require.resolve('babel-runtime/regenerator'), | ||
}, | ||
}; | ||
|
||
// Return the altered config | ||
return newConfig; | ||
}; | ||
module.exports = deprecate( | ||
createDefaultWebpackConfig, | ||
"importing default webpack config generator from '@storybook/react-native/dist/server/config/defaults/webpack.config.js' is deprecated. Use third argument of your exported function instead. See https://storybook.js.org/configurations/custom-webpack-config/#full-control-mode--default" | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import deprecate from 'util-deprecate'; | ||
import { createDefaultWebpackConfig } from '@storybook/core/server'; | ||
import { includePaths } from '../utils'; | ||
|
||
module.exports = storybookBaseConfig => | ||
createDefaultWebpackConfig(storybookBaseConfig, includePaths); | ||
module.exports = deprecate( | ||
createDefaultWebpackConfig, | ||
"importing default webpack config generator from '@storybook/react/dist/server/config/defaults/webpack.config.js' is deprecated. Use third argument of your exported function instead. See https://storybook.js.org/configurations/custom-webpack-config/#full-control-mode--default" | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import deprecate from 'util-deprecate'; | ||
import { createDefaultWebpackConfig } from '@storybook/core/server'; | ||
import { includePaths } from '../utils'; | ||
|
||
module.exports = storybookBaseConfig => | ||
createDefaultWebpackConfig(storybookBaseConfig, includePaths); | ||
module.exports = deprecate( | ||
createDefaultWebpackConfig, | ||
"importing default webpack config generator from '@storybook/vue/dist/server/config/defaults/webpack.config.js' is deprecated. Use third argument of your exported function instead. See https://storybook.js.org/configurations/custom-webpack-config/#full-control-mode--default" | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,28 +95,21 @@ You may want to keep Storybook's [default config](/configurations/default-config | |
If so, this is how you do it using the Full Control Mode. | ||
Add following content to the `webpack.config.js` in your Storybook config directory. | ||
|
||
> We plan to expose our default webpack-config as it's own package in the future. | ||
|
||
```js | ||
const path = require('path'); | ||
|
||
// load the default config generator. | ||
const genDefaultConfig = require('@storybook/react/dist/server/config/defaults/webpack.config.js'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be mentioned in docs as a deprecated feature? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDK, just have seen people leave deprecated features with some "deprecated" labels on them... But it's not critical to me 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if we don't want people to do something we delete it from the docs :) Unless it's something that we think a lot of people are already doing, in which case a deprecated note could help in some cases. But probably people who are already doing something are unlikely to come back to the docs, so really I don't think it gains much. |
||
|
||
module.exports = (baseConfig, env) => { | ||
const config = genDefaultConfig(baseConfig, env); | ||
|
||
// Extend it as you need. | ||
module.exports = (baseConfig, env, defaultConfig) => { | ||
// Extend defaultConfig as you need. | ||
|
||
// For example, add typescript loader: | ||
config.module.rules.push({ | ||
defaultConfig.module.rules.push({ | ||
test: /\.(ts|tsx)$/, | ||
include: path.resolve(__dirname, '../src'), | ||
loader: require.resolve('ts-loader') | ||
}); | ||
config.resolve.extensions.push('.ts', '.tsx'); | ||
defaultConfig.resolve.extensions.push('.ts', '.tsx'); | ||
|
||
return config; | ||
return defaultConfig; | ||
}; | ||
``` | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in case of full control mode, there is a first parameter that is extended with angular-cli's config, and the default config which is extended as well. Is this expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that you actually pick one or another, yes