Skip to content

Commit

Permalink
Merge pull request #792 from gaearon/babel-modules
Browse files Browse the repository at this point in the history
Babel plugin to instrument only correct files
  • Loading branch information
theKashey authored Jan 19, 2018
2 parents 8802f03 + 2d262f4 commit b8414d2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/styled-components/webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
module: {
rules: [
{
exclude: /node_modules|packages/,
//exclude: /node_modules|packages/, // should work without exclude
test: /\.js$/,
use: 'babel-loader',
},
Expand Down
15 changes: 9 additions & 6 deletions packages/react-hot-loader/src/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ module.exports = function plugin(args) {

Program: {
enter({ node, scope }, { file }) {
node.body.unshift(headerTemplate())
node[REGISTRATIONS] = [] // eslint-disable-line no-param-reassign

// Everything in the top level scope, when reasonable,
Expand All @@ -140,11 +139,15 @@ module.exports = function plugin(args) {
const registrations = node[REGISTRATIONS]
node[REGISTRATIONS] = null // eslint-disable-line no-param-reassign

// Inject the generated tagging code at the very end
// so that it is as minimally intrusive as possible.
node.body.push(t.emptyStatement())
node.body.push(buildTagger({ REGISTRATIONS: registrations }))
node.body.push(t.emptyStatement())
// inject the code only if applicable
if (registrations.length) {
node.body.unshift(headerTemplate())
// Inject the generated tagging code at the very end
// so that it is as minimally intrusive as possible.
node.body.push(t.emptyStatement())
node.body.push(buildTagger({ REGISTRATIONS: registrations }))
node.body.push(t.emptyStatement())
}
},
},
Class(classPath) {
Expand Down
Loading

0 comments on commit b8414d2

Please sign in to comment.