Skip to content

Commit

Permalink
Perf: bail out fast if input doesn't contain stylex
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Dec 6, 2023
1 parent 0e3cfb4 commit b350894
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/nextjs-plugin/src/custom-webpack-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

const PLUGIN_NAME = 'stylex';

module.exports = function stylexLoader(inputCode) {
module.exports = function stylexLoader(inputCode, inputSourceMap) {
const callback = this.async();

// bail out early if the input doesn't contain "stylex"
if (!inputCode.includes('stylex')) {
return callback(null, inputCode, inputSourceMap);
}

const { stylexPlugin } = this.getOptions();
const logger = this._compiler.getInfrastructureLogger(PLUGIN_NAME);

Expand Down
6 changes: 6 additions & 0 deletions packages/rollup-plugin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ module.exports = function stylexPlugin({
return false;
},
async transform(inputCode, id) {
// bail out early if the input doesn't contain "stylex"
if (!inputCode.includes('stylex')) {
// In rollup, returning null from any plugin phase means "no changes made".
return null;
}

const { code, map, metadata } = await babel.transformAsync(inputCode, {
babelrc: false,
filename: id,
Expand Down
8 changes: 7 additions & 1 deletion packages/webpack-plugin/src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@

const PLUGIN_NAME = 'stylex';

module.exports = function stylexLoader(inputCode) {
module.exports = function stylexLoader(inputCode, inputSourceMap) {
const callback = this.async();

// bail out early if the input doesn't contain "stylex"
if (!inputCode.includes('stylex')) {
return callback(null, inputCode, inputSourceMap);
}

const { stylexPlugin } = this.getOptions();
const logger = this._compiler.getInfrastructureLogger(PLUGIN_NAME);

Expand Down

0 comments on commit b350894

Please sign in to comment.