|
| 1 | +const path = require('path'); |
| 2 | + |
| 3 | +const root = path.resolve(__dirname, '..'); |
| 4 | +require('dotenv').config({ |
| 5 | + path: path.join(root, '.env') |
| 6 | +}); |
| 7 | + |
| 8 | +const BUILD_FOR_IE11 = process.env.UI5_WEBCOMPONENTS_FOR_REACT_BUILD_IE11 === 'true'; |
| 9 | + |
| 10 | +const DEPENDENCY_REGEX = BUILD_FOR_IE11 |
| 11 | + ? /node_modules/ |
| 12 | + : /node_modules\/(@ui5\/webcomponents(-(base|core|fiori|icons|theme-base))?|lit-html)\//; |
| 13 | + |
| 14 | +module.exports = { |
| 15 | + stories: ['../docs/**/*.stories.mdx', '../packages/**/*.stories.@(tsx|jsx|mdx)'], |
| 16 | + addons: [ |
| 17 | + '@storybook/addon-toolbars', |
| 18 | + '@storybook/addon-docs', |
| 19 | + '@storybook/addon-controls', |
| 20 | + '@storybook/addon-actions' |
| 21 | + ], |
| 22 | + webpack: async (config, { configType }) => { |
| 23 | + // `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION' |
| 24 | + // You can change the configuration based on that. |
| 25 | + // 'PRODUCTION' is used when building the static version of storybook. |
| 26 | + |
| 27 | + config.module.rules.push({ |
| 28 | + test: /assets\/.*\.json$/, |
| 29 | + use: 'file-loader', |
| 30 | + type: 'javascript/auto' |
| 31 | + }); |
| 32 | + |
| 33 | + if (configType === 'PRODUCTION' || BUILD_FOR_IE11) { |
| 34 | + config.module.rules.push({ |
| 35 | + test: /\.(js|mjs)$/, |
| 36 | + include: DEPENDENCY_REGEX, |
| 37 | + loader: 'babel-loader', |
| 38 | + options: { |
| 39 | + sourceType: 'unambiguous', |
| 40 | + babelrc: false, |
| 41 | + configFile: false, |
| 42 | + compact: false, |
| 43 | + presets: [ |
| 44 | + [ |
| 45 | + '@babel/preset-env', |
| 46 | + { |
| 47 | + // Allow importing core-js in entrypoint and use browserlist to select polyfills |
| 48 | + useBuiltIns: 'entry', |
| 49 | + // Set the corejs version we are using to avoid warnings in console |
| 50 | + // This will need to change once we upgrade to corejs@3 |
| 51 | + corejs: 3, |
| 52 | + // Do not transform modules to CJS |
| 53 | + modules: false, |
| 54 | + // Exclude transforms that make all code slower |
| 55 | + exclude: ['transform-typeof-symbol'] |
| 56 | + } |
| 57 | + ] |
| 58 | + ], |
| 59 | + plugins: [ |
| 60 | + [ |
| 61 | + '@babel/plugin-transform-runtime', |
| 62 | + { |
| 63 | + version: require('@babel/runtime/package.json').version, |
| 64 | + useESModules: true |
| 65 | + } |
| 66 | + ] |
| 67 | + ], |
| 68 | + cacheDirectory: true, |
| 69 | + cacheCompression: false, |
| 70 | + |
| 71 | + // If an error happens in a package, it's possible to be |
| 72 | + // because it was compiled. Thus, we don't want the browser |
| 73 | + // debugger to show the original code. Instead, the code |
| 74 | + // being evaluated would be much more helpful. |
| 75 | + sourceMaps: false |
| 76 | + } |
| 77 | + }); |
| 78 | + } |
| 79 | + config.resolve.alias = { |
| 80 | + ...config.resolve.alias, |
| 81 | + '@shared': path.join(root, 'shared'), |
| 82 | + '@ui5/webcomponents-react/dist': path.join(root, 'packages', 'main', 'dist'), |
| 83 | + '@ui5/webcomponents-react': path.join(root, 'packages', 'main', 'src'), |
| 84 | + '@ui5/webcomponents-react-charts': path.join(root, 'packages', 'charts', 'src'), |
| 85 | + '@ui5/webcomponents-react-base/types': path.join(root, 'packages', 'base', 'types'), |
| 86 | + '@ui5/webcomponents-react-base': path.join(root, 'packages', 'base', 'src') |
| 87 | + }; |
| 88 | + |
| 89 | + return config; |
| 90 | + } |
| 91 | +}; |
0 commit comments