From 8cee042e13a685ed02b4e9ed67c08e2c974a68ce Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 17 May 2020 16:23:23 +0200 Subject: [PATCH] packages/storybook: point to src/ and use sucrase --- packages/storybook/.storybook/main.js | 41 +++++++++++++-------------- packages/storybook/package.json | 4 +-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/packages/storybook/.storybook/main.js b/packages/storybook/.storybook/main.js index 7243452357..5f9bde16c3 100644 --- a/packages/storybook/.storybook/main.js +++ b/packages/storybook/.storybook/main.js @@ -15,15 +15,10 @@ module.exports = { webpackFinal: async (config) => { const coreSrc = path.resolve(__dirname, '../../core/src'); - config.resolve.alias = { - ...config.resolve.alias, - // Resolves imports of @backstage/core inside the storybook config, pointing to src - '@backstage/core': coreSrc, - // Point to dist version of theme and any other packages that might be needed in the future - '@backstage/theme': path.resolve(__dirname, '../../theme'), - }; + // Mirror config in packages/cli/src/lib/bundler + config.resolve.mainFields = ['main:src', 'browser', 'module', 'main']; - // Remove the default babel-loader for js files, we're using ts-loader instead + // Remove the default babel-loader for js files, we're using sucrase instead const [jsLoader] = config.module.rules.splice(0, 1); if (jsLoader.use[0].loader !== 'babel-loader') { throw new Error( @@ -33,20 +28,24 @@ module.exports = { config.resolve.extensions.push('.ts', '.tsx'); - // Use ts-loader for all JS/TS files - config.module.rules.push({ - test: /\.(ts|tsx|mjs|js|jsx)$/, - include: [__dirname, coreSrc], - exclude: /node_modules/, - use: [ - { - loader: require.resolve('ts-loader'), - options: { - transpileOnly: true, - }, + config.module.rules.push( + { + test: /\.(tsx?)$/, + exclude: /node_modules/, + loader: require.resolve('@sucrase/webpack-loader'), + options: { + transforms: ['typescript', 'jsx', 'react-hot-loader'], }, - ], - }); + }, + { + test: /\.(jsx?|mjs)$/, + exclude: /node_modules/, + loader: require.resolve('@sucrase/webpack-loader'), + options: { + transforms: ['jsx', 'react-hot-loader'], + }, + }, + ); // Disable ProgressPlugin which logs verbose webpack build progress. Warnings and Errors are still logged. config.plugins = config.plugins.filter( diff --git a/packages/storybook/package.json b/packages/storybook/package.json index 64be72bdcf..be449f91ed 100644 --- a/packages/storybook/package.json +++ b/packages/storybook/package.json @@ -4,8 +4,8 @@ "description": "Storybook build for core package", "private": true, "scripts": { - "start": "backstage-cli watch-deps --build -- start-storybook -p 6006", - "build-storybook": "backstage-cli watch-deps --build -- build-storybook --output-dir dist" + "start": "start-storybook -p 6006", + "build-storybook": "build-storybook --output-dir dist" }, "workspaces": { "nohoist": [