-
-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
babel-plugin-lodash #1088
babel-plugin-lodash #1088
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"presets": ["react-app"] | ||
} | ||
"presets": [ | ||
["react-app", { "isUsingLodash": false } ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know if it's really needed, followed @gaearon specs:
|
||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); | |
var url = require('url'); | ||
var paths = require('./paths'); | ||
var getClientEnvironment = require('./env'); | ||
var appPackageJson = require(paths.appPackageJson) | ||
|
||
function ensureSlash(path, needsSlash) { | ||
var hasSlash = path.endsWith('/'); | ||
|
@@ -31,12 +32,16 @@ function ensureSlash(path, needsSlash) { | |
} | ||
} | ||
|
||
// If `lodash` is present into app package.json we apply `babel-plugin-lodash` | ||
// through the `isUsingLodash` option of `babel-preset-react-app` to reduce build size | ||
var isUsingLodash = !!appPackageJson.dependencies.lodash | ||
|
||
// We use "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. | ||
var homepagePath = require(paths.appPackageJson).homepage; | ||
var homepagePath = appPackageJson.homepage; | ||
var homepagePathname = homepagePath ? url.parse(homepagePath).pathname : '/'; | ||
// Webpack uses `publicPath` to determine where the app is being served from. | ||
// It requires a trailing slash, or the file assets will get an incorrect path. | ||
|
@@ -149,7 +154,7 @@ module.exports = { | |
// @remove-on-eject-begin | ||
query: { | ||
babelrc: false, | ||
presets: [require.resolve('babel-preset-react-app')], | ||
presets: [[require.resolve('babel-preset-react-app'), {isUsingLodash: isUsingLodash}]], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to write only |
||
}, | ||
// @remove-on-eject-end | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to move the whole block to provide a function to
module.exports
in order to have access tooptions
object