diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index e860d9b04..6eb5b0502 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -8,32 +8,31 @@ * of patent rights can be found in the PATENTS file in the same directory. */ // @remove-on-eject-end -'use strict'; +'use strict' -const path = require('path'); -const fs = require('fs'); -const url = require('url'); +const path = require('path') +const fs = require('fs') +const url = require('url') // Make sure any symlinks in the project folder are resolved: // https://github.com/facebookincubator/create-react-app/issues/637 -const appDirectory = fs.realpathSync(process.cwd()); -const resolveApp = relativePath => path.resolve(appDirectory, relativePath); +const appDirectory = fs.realpathSync(process.cwd()) +const resolveApp = relativePath => path.resolve(appDirectory, relativePath) -const envPublicUrl = process.env.PUBLIC_URL; +const envPublicUrl = process.env.PUBLIC_URL function ensureSlash(path, needsSlash) { - const hasSlash = path.endsWith('/'); + const hasSlash = path.endsWith('/') if (hasSlash && !needsSlash) { - return path.substr(path, path.length - 1); + return path.substr(path, path.length - 1) } else if (!hasSlash && needsSlash) { - return `${path}/`; + return `${path}/` } else { - return path; + return path } } -const getPublicUrl = appPackageJson => - envPublicUrl || require(appPackageJson).homepage; +const getPublicUrl = appPackageJson => envPublicUrl || require(appPackageJson).homepage // We use `PUBLIC_URL` environment variable or "homepage" field to infer // "public path" at which the app is served. @@ -42,10 +41,9 @@ const getPublicUrl = appPackageJson => // We can't use a relative path in HTML because we don't want to load something // like /todos/42/static/js/bundle.7289d.js. We have to know the root. function getServedPath(appPackageJson) { - const publicUrl = getPublicUrl(appPackageJson); - const servedUrl = - envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); - return ensureSlash(servedUrl, true); + const publicUrl = getPublicUrl(appPackageJson) + const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/') + return ensureSlash(servedUrl, true) } // config after eject: we're in ./config/ @@ -63,10 +61,10 @@ module.exports = { appTsConfig: resolveApp('tsconfig.json'), publicUrl: getPublicUrl(resolveApp('package.json')), servedPath: getServedPath(resolveApp('package.json')), -}; +} // @remove-on-eject-begin -const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath); +const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath) // config before eject: we're in ./node_modules/react-scripts/config/ module.exports = { @@ -81,6 +79,7 @@ module.exports = { yarnLockFile: resolveApp('yarn.lock'), testsSetup: resolveApp('src/setupTests.ts'), appNodeModules: resolveApp('node_modules'), + rootNodeModules: path.resolve(appDirectory, '..', '..', 'node_modules'), appTsConfig: resolveApp('tsconfig.json'), appTsTestConfig: resolveApp('tsconfig.test.json'), publicUrl: getPublicUrl(resolveApp('package.json')), @@ -88,13 +87,12 @@ module.exports = { // These properties only exist before ejecting: ownPath: resolveOwn('.'), ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3 -}; +} -const ownPackageJson = require('../package.json'); -const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`); +const ownPackageJson = require('../package.json') +const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`) const reactScriptsLinked = - fs.existsSync(reactScriptsPath) && - fs.lstatSync(reactScriptsPath).isSymbolicLink(); + fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink() // config before publish: we're in ./packages/react-scripts/config/ if ( @@ -120,6 +118,6 @@ if ( // These properties only exist before ejecting: ownPath: resolveOwn('.'), ownNodeModules: resolveOwn('node_modules'), - }; + } } // @remove-on-eject-end diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 07c0a3adf..96d8828db 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -8,28 +8,28 @@ * of patent rights can be found in the PATENTS file in the same directory. */ // @remove-on-eject-end -'use strict'; +'use strict' -const autoprefixer = require('autoprefixer'); -const path = require('path'); -const webpack = require('webpack'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); -const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); -const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); -const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); -const getClientEnvironment = require('./env'); -const paths = require('./paths'); +const autoprefixer = require('autoprefixer') +const path = require('path') +const webpack = require('webpack') +const HtmlWebpackPlugin = require('html-webpack-plugin') +const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin') +const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin') +const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin') +const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin') +const getClientEnvironment = require('./env') +const paths = require('./paths') // Webpack uses `publicPath` to determine where the app is being served from. // In development, we always serve from the root. This makes config easier. -const publicPath = '/'; +const publicPath = '/' // `publicUrl` is just like `publicPath`, but we will provide it to our app // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript. // Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz. -const publicUrl = ''; +const publicUrl = '' // Get environment variables to inject into our app. -const env = getClientEnvironment(publicUrl); +const env = getClientEnvironment(publicUrl) // This is the development configuration. // It is focused on developer experience and fast rebuilds. @@ -110,9 +110,7 @@ module.exports = { // It usually still works on npm 3 without this but it would be // unfortunate to rely on, as react-scripts could be symlinked, // and thus babel-runtime might not be resolvable from the source. - 'babel-runtime': path.dirname( - require.resolve('babel-runtime/package.json') - ), + 'babel-runtime': path.dirname(require.resolve('babel-runtime/package.json')), // @remove-on-eject-end // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ @@ -126,6 +124,10 @@ module.exports = { // Make sure your source files are compiled, as they will not be processed in any way. new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), ], + symlinks: false, + }, + resolveLoader: { + symlinks: false, }, module: { strictExportPresence: true, @@ -140,7 +142,7 @@ module.exports = { test: /\.(ts|tsx)$/, loader: require.resolve('tslint-loader'), enforce: 'pre', - include: paths.appSrc, + include: [paths.appSrc, paths.rootNodeModules], }, { test: /\.js$/, @@ -167,7 +169,7 @@ module.exports = { // Compile .tsx? { test: /\.(ts|tsx)$/, - include: paths.appSrc, + include: [paths.appSrc, paths.rootNodeModules], loader: require.resolve('ts-loader'), }, // "postcss" loader applies autoprefixer to our CSS. @@ -278,4 +280,4 @@ module.exports = { performance: { hints: false, }, -}; +} diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 01bb852f5..4dfe27d41 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,22 +1,16 @@ { - "name": "react-scripts-ts", + "name": "@functionalfoundry/react-scripts-ts", "version": "2.8.0", "description": "Configuration and scripts for Create React App.", - "repository": "wmonk/create-react-app", + "repository": "functionalfoundry/create-react-app-typescript", "license": "BSD-3-Clause", "engines": { "node": ">=6" }, "bugs": { - "url": "https://github.com/wmonk/create-react-app/issues" + "url": "https://github.com/functionalfoundry/create-react-app-typescript/issues" }, - "files": [ - "bin", - "config", - "scripts", - "template", - "utils" - ], + "files": ["bin", "config", "scripts", "template", "utils"], "bin": { "react-scripts-ts": "./bin/react-scripts-ts.js" },