|
| 1 | +/* eslint-disable sort-keys */ |
1 | 2 |
|
2 |
| -// you can use this file to add your custom webpack plugins, loaders and anything you like. |
3 |
| -// This is just the basic way to add additional webpack configurations. |
4 |
| -// For more information refer the docs: https://storybook.js.org/configurations/custom-webpack-config |
5 |
| - |
6 |
| -// IMPORTANT |
7 |
| -// When you add this file, we won't add the default configurations which is similar |
8 |
| -// to "React Create App". This only has babel loader to load JavaScript. |
9 |
| - |
10 |
| -const path = require('path'); |
11 |
| -const genDefaultConfig = require('@storybook/react/dist/server/config/defaults/webpack.config.js'); |
12 |
| -const {getLocalIdent} = require('./helpers'); |
13 |
| -const paths = require('../config/paths'); |
14 |
| -const postcssConfig = require('../config/postcss.config'); |
15 |
| -const babelConfig = require('../config/babel.config'); |
16 |
| - |
17 |
| -module.exports = (baseConfig, env) => { |
18 |
| - const config = genDefaultConfig(baseConfig, env); |
| 3 | +module.exports = ({config}) => { |
19 | 4 | config.devtool = 'eval';
|
20 | 5 |
|
21 |
| - config.module.rules = [ |
22 |
| - { |
23 |
| - test: /\.js$/, |
24 |
| - loader: require.resolve('source-map-loader'), |
25 |
| - enforce: 'pre', |
26 |
| - include: paths.src, |
27 |
| - }, |
28 |
| - { |
29 |
| - // "oneOf" will traverse all following loaders until one will |
30 |
| - // match the requirements. When no loader matches it will fall |
31 |
| - // back to the "file" loader at the end of the loader list. |
32 |
| - oneOf: [ |
33 |
| - { |
34 |
| - test: /\.md$/, |
35 |
| - loader: 'raw-loader', |
36 |
| - }, |
37 |
| - // "url" loader works like "file" loader except that it embeds assets |
38 |
| - // smaller than specified limit in bytes as data URLs to avoid requests. |
39 |
| - // A missing `test` is equivalent to a match. |
40 |
| - { |
41 |
| - test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], |
42 |
| - loader: require.resolve('url-loader'), |
43 |
| - options: { |
44 |
| - limit: 10000, |
45 |
| - name: 'static/media/[name].[hash:8].[ext]', |
46 |
| - }, |
47 |
| - }, |
48 |
| - // Compile .tsx? |
49 |
| - { |
50 |
| - test: /\.(ts|tsx)$/, |
51 |
| - include: [paths.src, paths.stories], |
52 |
| - loader: require.resolve('babel-loader'), |
53 |
| - options: { |
54 |
| - babelrc: false, |
55 |
| - cacheDirectory: path.resolve(process.cwd(), '.cache'), |
56 |
| - ...babelConfig, |
57 |
| - }, |
58 |
| - }, |
59 |
| - // "postcss" loader applies autoprefixer to our CSS. |
60 |
| - // "css" loader resolves paths in CSS and adds assets as dependencies. |
61 |
| - // "style" loader turns CSS into JS modules that inject <style> tags. |
62 |
| - // In production, we use a plugin to extract that CSS to a file, but |
63 |
| - // in development "style" loader enables hot editing of CSS. |
64 |
| - { |
65 |
| - test: /\.css$/, |
66 |
| - use: [ |
67 |
| - require.resolve('style-loader'), |
68 |
| - { |
69 |
| - loader: require.resolve('css-loader'), |
70 |
| - options: { |
71 |
| - importLoaders: 1, |
72 |
| - modules: true, |
73 |
| - camelCase: true, |
74 |
| - localIdentName: '[name]__[local]', |
75 |
| - getLocalIdent, |
76 |
| - }, |
77 |
| - }, |
78 |
| - { |
79 |
| - loader: require.resolve('postcss-loader'), |
80 |
| - options: { |
81 |
| - // Necessary for external CSS imports to work |
82 |
| - // https://github.com/facebookincubator/create-react-app/issues/2677 |
83 |
| - ident: 'postcss', |
84 |
| - plugins: postcssConfig, |
85 |
| - }, |
86 |
| - }, |
87 |
| - ], |
88 |
| - }, |
89 |
| - { |
90 |
| - |
91 |
| - }, |
92 |
| - // "file" loader makes sure those assets get served by WebpackDevServer. |
93 |
| - // When you `import` an asset, you get its (virtual) filename. |
94 |
| - // In production, they would get copied to the `build` folder. |
95 |
| - // This loader don't uses a "test" so it will catch all modules |
96 |
| - // that fall through the other loaders. |
97 |
| - { |
98 |
| - // Exclude `js` files to keep "css" loader working as it injects |
99 |
| - // it's runtime that would otherwise processed through "file" loader. |
100 |
| - // Also exclude `html` and `json` extensions so they get processed |
101 |
| - // by webpacks internal loaders. |
102 |
| - exclude: [/\.js$/, /\.html$/, /\.json$/], |
103 |
| - loader: require.resolve('file-loader'), |
104 |
| - options: { |
105 |
| - name: 'static/media/[name].[hash:8].[ext]', |
106 |
| - }, |
107 |
| - }, |
108 |
| - ], |
109 |
| - }, |
110 |
| - // ** STOP ** Are you adding a new loader? |
111 |
| - // Make sure to add the new loader(s) before the "file" loader. |
112 |
| - ]; |
| 6 | + config.module.rules.push({ |
| 7 | + test: /\.(ts|tsx)$/, |
| 8 | + loader: require.resolve('babel-loader'), |
| 9 | + }); |
113 | 10 |
|
114 | 11 | config.resolve.extensions.push('.ts', '.tsx');
|
115 | 12 |
|
|
0 commit comments