-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ export default { | |
alias: { | ||
baseAlias: 'base-alias', | ||
}, | ||
modules: [], | ||
}, | ||
module: { | ||
noParse: /jquery/, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin'; | |
import { normalizeCondition } from 'webpack/lib/RuleSet'; | ||
import { logger } from '@storybook/node-logger'; | ||
|
||
const JSCONFIG = 'jsconfig.json'; | ||
const TSCONFIG = 'tsconfig.json'; | ||
|
||
const appDirectory = fs.realpathSync(process.cwd()); | ||
const cssExtensions = ['.css', '.scss', '.sass']; | ||
const cssModuleExtensions = ['.module.css', '.module.scss', '.module.sass']; | ||
const typeScriptExtensions = ['.ts', '.tsx']; | ||
|
@@ -14,7 +18,6 @@ let reactScriptsPath; | |
export function getReactScriptsPath({ noCache } = {}) { | ||
if (reactScriptsPath && !noCache) return reactScriptsPath; | ||
|
||
const appDirectory = fs.realpathSync(process.cwd()); | ||
let reactScriptsScriptPath = fs.realpathSync( | ||
path.join(appDirectory, '/node_modules/.bin/react-scripts') | ||
); | ||
|
@@ -106,6 +109,23 @@ export const getTypeScriptRules = (webpackConfigRules, configDir) => { | |
]; | ||
}; | ||
|
||
export const getModulePath = () => { | ||
// As with CRA, we only support `jsconfig.json` if `tsconfig.json` doesn't exist. | ||
let configName; | ||
if (fs.existsSync(path.join(appDirectory, TSCONFIG))) { | ||
configName = TSCONFIG; | ||
} else if (fs.existsSync(path.join(appDirectory, JSCONFIG))) { | ||
configName = JSCONFIG; | ||
} | ||
|
||
if (configName) { | ||
// eslint-disable-next-line import/no-dynamic-require,global-require | ||
const config = require(path.join(appDirectory, configName)); | ||
return config.compilerOptions && config.compilerOptions.baseUrl; | ||
} | ||
return false; | ||
}; | ||
|
||
function mergePlugins(basePlugins, additionalPlugins) { | ||
return [...basePlugins, ...additionalPlugins].reduce((plugins, plugin) => { | ||
if ( | ||
|
@@ -146,6 +166,10 @@ export function applyCRAWebpackConfig(baseConfig, configDir) { | |
const tsExtensions = hasTsSupport ? typeScriptExtensions : []; | ||
const extensions = [...cssExtensions, ...tsExtensions]; | ||
|
||
// Support for this was added in `[email protected]`. | ||
// https://github.com/facebook/create-react-app/pull/6656 | ||
const modulePath = isReactScriptsInstalled('3.0.0') && getModulePath(); | ||
|
||
// Remove any rules from baseConfig that test true for any one of the extensions | ||
const filteredBaseRules = baseConfig.module.rules.filter( | ||
rule => !rule.test || !extensions.some(normalizeCondition(rule.test)) | ||
|
@@ -175,6 +199,7 @@ export function applyCRAWebpackConfig(baseConfig, configDir) { | |
resolve: { | ||
...baseConfig.resolve, | ||
extensions: [...baseConfig.resolve.extensions, ...tsExtensions], | ||
modules: baseConfig.resolve.modules.concat(modulePath || []), | ||
}, | ||
resolveLoader: { | ||
modules: ['node_modules', path.join(getReactScriptsPath(), 'node_modules')], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
SKIP_PREFLIGHT_CHECK=true | ||
NODE_PATH=src | ||
NODE_PATH=src |