Skip to content
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

How to make CRACO watch for specific node modules package? #463

Closed
tal-rofe opened this issue Nov 6, 2022 · 2 comments
Closed

How to make CRACO watch for specific node modules package? #463

tal-rofe opened this issue Nov 6, 2022 · 2 comments

Comments

@tal-rofe
Copy link

tal-rofe commented Nov 6, 2022

I want CRACO to watch specific package changes (as it is a private package in my monorepo environment..).
So I configured craco:

import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import type { CracoConfig } from '@craco/craco';

const config: CracoConfig = {
	eslint: { enable: false },
	plugins: [
		{
			plugin: {
				overrideWebpackConfig: ({ webpackConfig }) => {
					webpackConfig.resolve!.plugins!.push(
						new TsconfigPathsPlugin({
							configFile: './tsconfig.base.json',
							extensions: ['.ts'],
						}),
					);

					return webpackConfig;
				},
			},
		},
	],
	devServer: {
		watchOptions: {
			ignored: /node_modules\/(?!@blabla\/common)/,
		},
	},
};

export default config;

I guess you should only relate to devServer key. But when I try to run CRACO I get:

cross-env BROWSER=none craco start
craco:  *** Cannot find ESLint plugin (ESLintWebpackPlugin). ***
Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'watchOptions'. These properties are valid:
   object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, setupMiddlewares?, static?, watchFiles?, webSocketServer? }
 ELIFECYCLE  Command failed with exit code 1.
 ```
@zanemcca
Copy link

I use something like this:

class WatchExternalFilesPlugin {
    apply(compiler) {
        compiler.hooks.afterCompile.tapAsync(
        'WatchExternalFilesPlugin',
        (compilation, callback) => {
            [
                path.join(__dirname, 'your-directory-of-interest'),
            ].forEach(path => compilation.contextDependencies.add(path));
            callback();
        });
    }
}

Along with a webpackConfig.plugins.push(new WatchExternalFilesPlugin()); call in my craco.config.js

@tal-rofe
Copy link
Author

As I changed to other package, this issue is no longer relevant to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants