-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from JeffreyMFarley/webpack-3
chore: Move to Webpack 3. Closes #25
- Loading branch information
Showing
21 changed files
with
4,421 additions
and
2,035 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
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
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
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,10 +1,12 @@ | ||
const path = require( 'path' ); | ||
|
||
|
||
const path = require('path'); | ||
|
||
// This is a custom Jest transformer turning file imports into filenames. | ||
// http://facebook.github.io/jest/docs/tutorial-webpack.html | ||
|
||
module.exports = { | ||
process( src, filename ) { | ||
return 'module.exports = ' + JSON.stringify( path.basename( filename ) ) + ';'; | ||
} | ||
process(src, filename) { | ||
return `module.exports = ${JSON.stringify(path.basename(filename))};`; | ||
}, | ||
}; |
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,78 +1,55 @@ | ||
var path = require( 'path' ); | ||
var fs = require( 'fs' ); | ||
var url = require( 'url' ); | ||
|
||
// Make sure any symlinks in the project folder are resolved: | ||
// https://github.com/facebookincubator/create-react-app/issues/637 | ||
var appDirectory = fs.realpathSync( process.cwd() ); | ||
function resolveApp( relativePath ) { | ||
return path.resolve( appDirectory, relativePath ); | ||
} | ||
|
||
// We support resolving modules according to `NODE_PATH`. | ||
// This lets you use absolute paths in imports inside large monorepos: | ||
// https://github.com/facebookincubator/create-react-app/issues/253. | ||
|
||
// It works similar to `NODE_PATH` in Node itself: | ||
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders | ||
|
||
// We will export `nodePaths` as an array of absolute paths. | ||
// It will then be used by Webpack configs. | ||
// Jest doesn’t need this because it already handles `NODE_PATH` out of the box. | ||
|
||
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. | ||
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. | ||
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421 | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const url = require('url'); | ||
|
||
var nodePaths = ( process.env.NODE_PATH || '' ) | ||
.split( process.platform === 'win32' ? ';' : ':' ) | ||
.filter( Boolean ) | ||
.filter( folder => !path.isAbsolute( folder ) ) | ||
.map( resolveApp ); | ||
|
||
var envPublicUrl = process.env.PUBLIC_URL; | ||
|
||
function ensureSlash( pathname, needsSlash ) { | ||
var hasSlash = pathname.endsWith( '/' ); | ||
if ( hasSlash && !needsSlash ) { | ||
return pathname.substr( pathname, pathname.length - 1 ); | ||
} else if ( !hasSlash && needsSlash ) { | ||
return pathname + '/'; | ||
// 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 envPublicUrl = process.env.PUBLIC_URL; | ||
|
||
function ensureSlash(path, needsSlash) { | ||
const hasSlash = path.endsWith('/'); | ||
if (hasSlash && !needsSlash) { | ||
return path.substr(path, path.length - 1); | ||
} else if (!hasSlash && needsSlash) { | ||
return `${path}/`; | ||
} else { | ||
return path; | ||
} | ||
return pathname; | ||
|
||
} | ||
|
||
function getPublicUrl( appPackageJson ) { | ||
return 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. | ||
// Webpack needs to know it to put the right <script> hrefs into HTML even in | ||
// single-page apps that may serve index.html for nested URLs like /todos/42. | ||
// 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 ) { | ||
var publicUrl = getPublicUrl( appPackageJson ); | ||
var servedUrl = envPublicUrl || ( | ||
publicUrl ? url.parse( publicUrl ).pathname : '/' | ||
); | ||
return ensureSlash( servedUrl, true ); | ||
function getServedPath(appPackageJson) { | ||
const publicUrl = getPublicUrl(appPackageJson); | ||
const servedUrl = | ||
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); | ||
return ensureSlash(servedUrl, true); | ||
} | ||
|
||
// config after eject: we're in ./config/ | ||
module.exports = { | ||
appBuild: resolveApp( 'ccdb5_ui/static' ), | ||
appPublic: resolveApp( 'public' ), | ||
appHtml: resolveApp( 'public/index.html' ), | ||
appIndexJs: resolveApp( 'src/App.jsx' ), | ||
appPackageJson: resolveApp( 'package.json' ), | ||
appSrc: resolveApp( 'src' ), | ||
yarnLockFile: resolveApp( 'yarn.lock' ), | ||
testsSetup: resolveApp( 'src/setupTests.js' ), | ||
appNodeModules: resolveApp( 'node_modules' ), | ||
nodePaths: nodePaths, | ||
publicUrl: getPublicUrl( resolveApp( 'package.json' ) ), | ||
servedPath: getServedPath( resolveApp( 'package.json' ) ) | ||
dotenv: resolveApp('.env'), | ||
appBuild: resolveApp('ccdb5_ui/static'), | ||
appPublic: resolveApp('public'), | ||
appHtml: resolveApp('public/index.html'), | ||
appIndexJs: resolveApp('src/index.js'), | ||
appPackageJson: resolveApp('package.json'), | ||
appSrc: resolveApp('src'), | ||
yarnLockFile: resolveApp('yarn.lock'), | ||
testsSetup: resolveApp('src/setupTests.js'), | ||
appNodeModules: resolveApp('node_modules'), | ||
publicUrl: getPublicUrl(resolveApp('package.json')), | ||
servedPath: getServedPath(resolveApp('package.json')), | ||
}; |
Oops, something went wrong.