Git Product home page Git Product logo

cra-build-watch's Introduction

cra-build-watch

A script for create-react-app that writes development builds to the disk

semantic-release code style: prettier Commitizen friendly Build Status npm version dependabot License: MIT

Disclaimer

The builds resulting from this script are NOT for production environment. They lack various optimizations.

This script is meant as a temporary workaround for create-react-app project based until this feature is built-in into react-scripts. See create-react-app#1070.

This script is inspired by other work related such as: https://gist.github.com/jasonblanchard/ae0d2e304a647cd847c0b4493c2353d4.

Ejection

You do not need to eject your project for you to use cra-build-watch.

This tool handles ejected projects but it assumes you did not modify your webpack.config.js file, paths.js and env.js utils. If you did I cannot guarantee that this tool will work.

Why do I need this?

As of now (20/04/2018), create-react-app (more precisely react-scripts) does not allow development builds to be written to the disk because it uses webpackDevServer to serve your build files and folders (for good reasons). The problem is that in some cases you need to have these files written to the disk i.e:

  • Developing browser extensions using React.
  • Incorporating your React application into an existing application.
  • Serving your React app with a dedicated backend.

Prerequisites

Supports react-scripts >= 1.0.x, hence it supports the newest version 4.x.x.

Supports node >= 10.

Installation

Add it to your project using npm:

npm install -D cra-build-watch

or using yarn:

yarn add -D cra-build-watch

Usage

Add a new script into your package.json:

{
  "scripts": {
    "watch": "cra-build-watch"
  }
}

Run that script:

npm run watch

with Yarn:

yarn watch

Configuration

By default the script will generate everything into build/ at your project root and remove the public path from webpack's configuration.

If those defaults do not work for you, the script accepts some arguments:

  • --after-initial-build-hook: accepts a string of shell code that will be run only once after the initial build in the same process as the cra-build-watch.
  • --after-rebuild-hook: accepts a string of shell code that will be run every time webpack rebuilds your project after a filesystem change. It runs in the same process as cra-build-watch.
  • -b|--build-path: expects either an absolute or relative path. If a relative path is given it will be prefixed by your project root path.
    • default: yourProjectRoot/build.
  • --chunk-filename: Set the naming you want to use for non-entry chunk files. Accepts webpack placeholders such as [id], [name], [hash]. Directories can be supplied.
    • default: js/bundle.js.
  • --disable-chunks: disable code-splitting / chunks so that only a single bundle.js file is generated. It only works with react-scripts >= 2.0.0.
  • -o|--output-filename: Set the name to be used for the output bundle. Accepts webpack placeholders such as [id], [name], [hash]. Directories can be supplied.
    • default: js/[name].chunk.js
  • --react-scripts-version: expects the react-scripts version you are using in your project i.e 2.0.3. If not given it will be implied from your node_modules and if it cannot be implied the version 2.1.2 will be the default. Consider setting it if you ejected and are not using the latest react-scripts version.
  • -p|--public-path: expects a relative URL where / is the root. If you serve your files using an external webserver this argument is to match with your web server configuration. More information can be found in webpack configuration guide.
    • default: "".
  • -v|--verbose: display webpack build output.

Contributions

All contributions are welcomed.

cra-build-watch's People

Contributors

alexomanie avatar dependabot-preview[bot] avatar devxpy avatar hexnaught avatar jeremygooch avatar jordanmkoncz avatar looseend avatar nargonath avatar tavikukko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cra-build-watch's Issues

%PUBLIC_URL% is not affected by --public-path

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: v12.13.1
  • module version with issue: v3.4.0
  • last module version without issue: none
  • environment (e.g. node, browser, native): browser
  • used with (e.g. hapi application, another framework, standalone, ...): just cra
  • any other relevant information: -

What are you trying to achieve or the steps to reproduce?

I need all references (js, css, favicon etc.) to be relative to the current folder, not to root as it's by default.
For production build (npm run build), I can "homepage": "./" to package.json.
It would be nice if cra-build-watch would pick up this parameter as well, but I found a workaround almost as good:
using cra-build-watch --public-path ./.
Unfortunately, while js and css references are relative, %PUBLIC_URL% is not replaced with ./, so I get:

What was the result you got?

<link rel="icon" href="/favicon.ico" />
...
<script src="./js/bundle.js">

For favicon defined just as in the default cra:
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />

What result did you expect?

<link rel="icon" href="./favicon.ico" />
...
<script src="./js/bundle.js">

Investigate for hot reloading

Hot reloading is lost because I had to remove webpack dev server from CRA configuration in order to write the project files to the disk hence losing hot reloading feature. Let's see if there is a way to bring it back either through special mode with WDS or with a custom method.

The automated release is failing 🚨

🚨 The automated release from the beta branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the beta branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

[Feature Request] Create a dev build without a watcher

Why I need this:
I want to be able to create a single build for each time django renders a template.
A file watcher has to be started and maintained throughout the course of the django server's lifetime. On the other hand, we can just do a build each time django renders a template, since its development. This will also ensure any files that might have been missed by the file watcher.

API suggestion
cra-build-watch --no-watch

I'm a python guy and have a limited knowledge of webpack. However, I am ready to help if you can point me in the right direction.

Thanks/

Plugin could not be registered at 'html-webpack-plugin-before-html-proces sing'. Hook was not found.

Getting this error when I try and run 'watch'.

I'm using react-app-rewired wonder if that's the problem


(node:11144) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.
hooks` instead
(node:11144) DeprecationWarning: Tapable.apply is deprecated. Call apply on the
plugin directly instead
Error: Plugin could not be registered at 'html-webpack-plugin-before-html-proces
sing'. Hook was not found.
BREAKING CHANGE: There need to exist a hook at 'this.hooks'. To create a compati
blity layer for this hook, hook into 'this._pluginCompat'.
    at Compilation.plugin (C:\workspace\client\client\node_modules\webpack\node_
modules\tapable\lib\Tapable.js:63:9)
    at Compilation.deprecated [as plugin] (internal/util.js:47:15)
    at compiler.plugin.compilation (C:\workspace\client\client\node_modules\reac
t-dev-utils\InterpolateHtmlPlugin.js:26:19)
    at SyncHook.eval [as call] (eval at create (C:\workspace\client\client\node_
modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:17:12), <anonymous>:
7:1)
    at SyncHook.lazyCompileHook [as _call] (C:\workspace\client\client\node_modu
les\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at Compiler.newCompilation (C:\workspace\client\client\node_modules\webpack\
lib\Compiler.js:434:26)
    at hooks.beforeCompile.callAsync.err (C:\workspace\client\client\node_module
s\webpack\lib\Compiler.js:473:29)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\workspace\client\
client\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12),
<anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (C:\workspace\client\clie
nt\node_modules\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at Compiler.compile (C:\workspace\client\client\node_modules\webpack\lib\Com
piler.js:468:28)
    at compiler.hooks.watchRun.callAsync.err (C:\workspace\client\client\node_mo
dules\webpack\lib\Watching.js:77:18)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\workspace\client\
client\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12),
<anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (C:\workspace\client\clie
nt\node_modules\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at Watching._go (C:\workspace\client\client\node_modules\webpack\lib\Watchin
g.js:40:32)
    at Watching.compiler.readRecords.err (C:\workspace\client\client\node_module
s\webpack\lib\Watching.js:32:9)
    at Compiler.readRecords (C:\workspace\client\client\node_modules\webpack\lib
\Compiler.js:338:11)
error An unexpected error occurred: "Command failed.
Exit code: 1
Command: C:\\WINDOWS\\system32\\cmd.exe
Arguments: /d /s /c cra-build-watch
Directory: C:\\workspace\\client\\client
Output:
".

[BUG] Output file structure looks different than "npm run build"

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): yes/no, I don't know what you mean by "affecting a production system"

Context

  • node version: v10.22.0
  • module version with issue: 3.4.0
  • last module version without issue: ?
  • environment (e.g. node, browser, native): node/browser
  • used with (e.g. hapi application, another framework, standalone, ...): Flask backend, Create-React-App
  • any other relevant information: This is on https://repl.it, but that shouldn't be affecting this

What are you trying to achieve or the steps to reproduce?

I'm trying to use cra-build-watch to auto build my create-react-app, but the file structure of the build-watch is different than the file structure, which doesn't work for development since the Flask backend requires ./client/build/static/ to be the static files folder (client is the folder with the React app).

What was the result you got?

./build
-- /js
---- 0.chunk.js
---- 0.chunk.js.map
---- 1.chunk.js
---- 1.chunk.js.map
---- bundle.chunk.js
---- bundle.chunk.js.map
---- main.chunk.js
---- main.chunk.js.map
-- asset-manifest.json
-- favicon.ico
-- index.html
-- logo192.png
-- logo512.png
-- manifest.json
-- robots.txt

What result did you expect?

I expected there to be a ./static/ folder with ./js inside of it.

./build
-- /static
---- /css
------ main.a_hash.chunk.css
------ main.a_hash.chunk.css.map
---- /js
------ 2.a_hash.chunk.js
------ 2.a_hash.chunk.js.LICENSE.txt
------ 2.a_hash.chunk.js.map
------ main.a_hash.chunk.js
------ main.a_hash.chunk.js.map
------ runtime-main.a_hash.chunk.js
------ runtime-main.a_hash.chunk.js.map
-- asset-manifest.json
-- favicon.ico
-- index.html
-- logo192.png
-- logo512.png
-- manifest.json
-- robots.txt

Note:

Even when I change my script to:

{
  "scripts": {
    "watch": "cra-build-watch -b ./build/static"
  }
}

it just makes the same directory structure as the first tree, except everything is in the ./build/static/ folder, not just the JavaScript and CSS (the CSS also never seems to appear?)

Create CSS file

Hi

With react-scripts build, the asset-manifest.json contains these lines among others:

{
  "files": {
    "main.css": "./static/css/main.d626b3da.chunk.css",
    "main.js": "./static/js/main.22ef37af.chunk.js"
  }
}

With cra-build-watch, the asset-manifest.json contains these lines:

{
  "files": {
    "main.js": "/js/bundle.js",
    "main.js.map": "/js/bundle.js.map",
    "index.html": "/index.html"
  },
  "entrypoints": [
    "js/bundle.js"
  ]
}

main.css is missing

Is it possible to generate main.css with cra-build-watch?

[BUG] When providing `-b` arg, the folder is not completely rebuilt, but copied in to.

When providing a build path with -b, the path does not get cleared as it does when the argument is omitted.

The asset-manifest is deleted and re-created so there is no risk (read very little, there is always a risk πŸ˜‰) of a build using the wrong files so expected current impact of the bug is minimal.


Examples;

Running with -b arg

cra-build-watch -b dist/ --chunk-filename './test_1/[name].[hash].js'
cra-build-watch -b dist/ --chunk-filename './test_2/[name].[hash].js'

+---dist
|   |   asset-manifest.json
|   |   favicon.ico
|   |   index.html
|   |   manifest.json
|   |   
|   +---js
|   |       bundle.js
|   |       bundle.js.map
|   |       
|   +---test_1
|   |       0.04b6ae9291b3834ef72a.js
|   |       0.04b6ae9291b3834ef72a.js.map
|   |       main.04b6ae9291b3834ef72a.js
|   |       main.04b6ae9291b3834ef72a.js.map
|   |       
|   \---test_2
|           0.04b6ae9291b3834ef72a.js
|           0.04b6ae9291b3834ef72a.js.map
|           main.04b6ae9291b3834ef72a.js
|           main.04b6ae9291b3834ef72a.js.map

Running without -b arg

cra-build-watch --chunk-filename './test_1/[name].[hash].js'
cra-build-watch --chunk-filename './test_2/[name].[hash].js'

+---build
|   |   asset-manifest.json
|   |   favicon.ico
|   |   index.html
|   |   manifest.json
|   |   
|   +---js
|   |       bundle.js
|   |       bundle.js.map
|   |       
|   \---test_2
|           0.04b6ae9291b3834ef72a.js
|           0.04b6ae9291b3834ef72a.js.map
|           main.04b6ae9291b3834ef72a.js
|           main.04b6ae9291b3834ef72a.js.map

How to utilize output to incorporate React application into an existing application?

Hi @Nargonath, first of all, thanks for the great work!

Secondly, I see in the main page that you state this project can be utilized for:

Incorporating your React application into an existing application.

This is exactly what I am attempting to do -- I have an Angular application which is currently integrated with React and I'm trying to figure out a way to utilize our existing React codebase directly from within this Angular project.

Being the build toolchain for the React app is far removed from Angular (and I really don't feel like replicating the entire configuration into our Angular app) -- I figured it may be possible to create a debug build of the React application, essentially pre-building it into a state where I might be able to do something like:

const ComponentFromReact = require('main.chunk').ComponentFromReact

Due to my inexperience with webpack, I had hoped it would be this easy, though clearly it is not. Is my intention an unreasonable pipe dream, or do you have any suggestions on how it may be accomplished?

Thanks!

-CJ

The automated release is failing 🚨

🚨 The automated release from the deploy branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the deploy branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Build a bot that open an issue on every new CRA version

The first version could be simple so it opens an issue on every new version.

A better version could check if the changes impact this package.json:

  • Perhaps check the changelog to see if react-scripts is concerned by the new version.
  • Could check the file contents to search for the index but that would be harder and perhaps not even doable.

cra-build-watch with react-app-rewired

I'm trying to use cra-build-watch with react-app-rewired because I need to disable the chunking of files and just have static files (among other config changes). This doesn't seem to work with cra-build-watch. Is there an option for this?

react-app-rewired cra-build-watch

Unknown script "cra-build-watch".

Add parameter to skip initial cleanup

Hello!

First of all thanks for this tool. It's helpful.

I would like to add the possibility to skip the initial cleanup by introducing --skip-cleanup param.

When I do the cleanup and copy some files into the build folder by another watch script before running cra-build-watch, I would like to be able to skip the cleanup made by cra-build-watch.

PR will follow this issue.
Thanks.

react-scripts v4 support?

Will this project be updated to support react-scripts v4?

When running with react-scripts v4, I get the following error:

my-project/node_modules/cra-build-watch/scripts/index.js:55
config.entry = config.entry.filter(fileName => !fileName.match(/webpackHotDevClient/));
                            ^

TypeError: config.entry.filter is not a function
    at Object.<anonymous

Change config.output.filename?

Hi!
Is it possible to change the location of the config.output.filename and config.output.chunkFilename so that it is the same as with the build on production?

Issue with main.chunk.js build on every other save?

This library is great, thank you!

I have an issue where I'm serving up my React dev build from a Phoenix server. It's working fine, but only on every other save in my React project. I found that every time I save a change,
the last line in my build/js/main.chunk.js alternates from

},[[0,"runtime-main",0]]]);

to

},[[0,"runtime-main",1]]]);

Phoenix serves up everything when it's 0, but not when it's 1. Does anyone know what this code is doing and whether it might be possible to have it return 0 always? I've tried looking at webpack docs but having trouble understanding what is going on here.
Thank you for any ideas!
-Dan

PUBLIC_URL isn't replaced in index.html

After the build using this tool, I still see <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> in index.html. Is there a way to easily fix this?

Can I be notified when CRA rebuilds?

I want to be notified to implement something to reload the page, with socket or something, getting the behavier as we have on normal "npm start".

I need the dev bundle, to be served by others application.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

The automated release is failing 🚨

🚨 The automated release from the deploy branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the deploy branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Beta version does not work for me

After updating to react-scripts 5 I am unable to use cra-build-watch, which for me worked really well.
As part of the investigation to resolve I found your suggestion to try the beta and so I did.
The installation and update of the webpack config succeeded but failed the start.

  • is this issue currently blocking your project? (no):
  • is this issue affecting a production system? (no):

Context

  • node version: 16.13.1
  • module version with issue:
  • last module version without issue:
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): react-scripts 5, webpack 5.66
  • any other relevant information:

What was the result you got?

rimraf ./build && react-scripts start

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.

  • options has an unknown property 'writeToDisk'. 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? }

What result did you expect?

To be able to run react-scripts start and see the build folder being generated

Can I use it with rescripts ?

I need to use rescripts to overried some configuration from CRA... in this case to allow use namespaces on CRA.

Cra build watch, try run

"start": "react-scripts start",

but my script is
"start": "rescripts start",

Thank you

Use this on non-ejected project?

Sorry if I missed this in the README, but I'd like to know if I can use cra-build-watch on my project if I haven't run eject. I'd rather not lose the functionality of CRA scripts so I don't want to eject but cra-build-watch sounds like exactly what I need.

Edit -- Could someone label this as a question? I believe I can't do it on my end

TypeError: x.trim is not a function

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: v15.9.0
  • module version with issue: 3.4.0
  • last module version without issue: unknown
  • environment (e.g. node, browser, native): WSL2 Ubuntu
  • used with (e.g. hapi application, another framework, standalone, ...): react
  • any other relevant information: -

What are you trying to achieve or the steps to reproduce?

I'm trying to npm run watch

What was the result you got?

❯ npm run watch

[email protected] watch
cra-build-watch

/home/df/work/ts_sandbox/node_modules/camelcase/index.js:35
.map(x => x.trim())
^

TypeError: x.trim is not a function
at /home/df/work/ts_sandbox/node_modules/camelcase/index.js:35:16
at Array.map ()
at module.exports (/home/df/work/ts_sandbox/node_modules/camelcase/index.js:35:5)
at /home/df/work/ts_sandbox/node_modules/camelcase-keys/index.js:55:17
at mapObject (/home/df/work/ts_sandbox/node_modules/map-obj/index.js:34:28)
at module.exports (/home/df/work/ts_sandbox/node_modules/map-obj/index.js:53:9)
at camelCaseConvert (/home/df/work/ts_sandbox/node_modules/camelcase-keys/index.js:68:9)
at module.exports (/home/df/work/ts_sandbox/node_modules/camelcase-keys/index.js:76:9)
at meow (/home/df/work/ts_sandbox/node_modules/meow/index.js:180:16)
at Object. (/home/df/work/ts_sandbox/node_modules/cra-build-watch/utils/cliHandler.js:5:18)
npm ERR! code 1
npm ERR! path /home/df/work/ts_sandbox
npm ERR! command failed
npm ERR! command sh -c cra-build-watch

What result did you expect?

Successfull run

Not working with [email protected]

Support plan

  • is this issue currently blocking your project? (yes/no): Yes
  • is this issue affecting a production system? (yes/no): No

Context

  • node version: 15.2.1
  • module version with issue: 3.4.0
  • last module version without issue: -
  • environment (e.g. node, browser, native): browser
  • used with (e.g. hapi application, another framework, standalone, ...): -
  • any other relevant information: [email protected]

What are you trying to achieve or the steps to reproduce?

The cra-build-watch ends with error if I'm using [email protected] which I need to use because of emotion and new jsx pragma system in react 17.

What was the result you got?

The error:

yarn run v1.22.5
$ cra-build-watch

- Update webpack configurationC:\Projects\_InQool\jch2\web\node_modules\cra-build-watch\scripts\index.js:98
  config.module.rules[oneOfIndex].oneOf[0].options.name = `media/[name].[hash:8].[ext]`;
                                       ^

TypeError: Cannot read property '0' of undefined
    at Object.<anonymous> (C:\Projects\_InQool\jch2\web\node_modules\cra-build-watch\scripts\index.js:98:40)
    at Module._compile (node:internal/modules/cjs/loader:1102:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
    at Module.load (node:internal/modules/cjs/loader:967:32)
    at Function.Module._load (node:internal/modules/cjs/loader:807:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

What result did you expect?

No error.

It seems that a different -b path copies some files but not others

I'm currently build-watching an application that has manifest.json and favicon.ico in public/. When I run cra-build-watch -b someotherpath then I find:

root/build/
    manifest.jsn
    favicon.ico
root/someotherpath
    index.html
    ...rest

Is this intended?

I've also tried to run: cra-build-watch -b someotherpath -p someotherpath but it doesn't seem to change anything.

What version supports build hooks

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 12.6
  • module version: 3.2
  • environment (e.g. node, browser, native): MacOS Catalina
  • used with (e.g. hapi application, another framework, standalone, ...):
  • any other relevant information:

How can we help?

I'm on a project that uses cra-build-watch version 3.2. I tried to add arguments for build hook, but they don't work. Whether I specified initial build hook or rebuild hook, cra-build-watch just rebuilds files but codes after those build hook arguments are not run.

At first, I thought it was due to the project being ejected, but I tried upgrading cra-build-watch to 3.4 and it works.

So I would like to know if this issue is due to 3.2 not supporting build hooks, or something about my project's configurations.

cannot find react-scripts/config/paths when running on cra 3.4.1

running cra-build-watch i get

> cra-build-watch

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'react-scripts/config/paths'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)

running it using cra-build-watch --react-scripts-version=3.4.1 did not work either. any suggestions?

application does not work with pathes in the URL with react BrowserRouter on initial invocation

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 14.15
  • module version:
  • environment (e.g. node, browser, native): browser
  • used with (e.g. hapi application, another framework, standalone, ...): react BrowserRouter
  • any other relevant information:

What problem are you trying to solve?

I am using your great tool in a CI environment to build a dev version of my app. I let the watcher run and rerminate it with the completed hook to get a build in my build directory. This is then served afterwards by gitlab pages or standalone by an ngings server.
This is working so far great. I have only an issue with pathes. When I access the application served on root path via nginx
like https://subdomain.mydomain.com its works fine and also the routes in teh application are resolved, as they should.
But when I invoke the application with one of this routed pathes like https://subdomain.mydomain.com/show/UIDV4
the page is not displayed. In fact no code is loaded.
But the application works fine in the same configuration, when I use the usal production build, or when I start it under node with npm react-scripts start

Do you have a new or modified API suggestion to solve the problem?

Examples for using build hooks with cra-build-watch

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 12.16
  • module version: 3.2
  • environment (e.g. node, browser, native): Node, on MacOS Catalina
  • used with (e.g. hapi application, another framework, standalone, ...): CRA
  • any other relevant information:

How can we help?

I'd like to see followable example for using cra-build-watch with build hooks (both initial and rebuild). Currently, I'm unable to get it to run after either an initial build or rebuild. I only get a Webpack build output.

Not compatible with react-scripts v5

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 16.5.0
  • module version with issue: 3.4.0
  • last module version without issue: unknown
  • environment (e.g. node, browser, native): macOS 12.1
  • used with (e.g. hapi application, another framework, standalone, ...): react
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

Add a script to package.json:

{
  "scripts": {
    "watch": "cra-build-watch"
  }
}

Run the command

yarn watch

What was the result you got?

Got the following error

 config.module.rules[oneOfIndex].oneOf[0].options.name = `media/[name].[hash:8].[ext]`;
                                                        ^
                                                        
TypeError: Cannot set property 'name' of undefined

What result did you expect?

No Error

creating development build without watch

Hey! I just want to create development build without running webpack watch.
I want to be able to create development build of CRA once and then deploy it on Vercel/Netlify.
Is there any easy way to do this?

Watch multiple applications

Hi!

We're using webpack to create react applications to incoroprate it into existing applications so your plugins sounds perfect.

We're creating multiple applications like this:

entry: {
  app1: paths.app1,
  app2: paths.app2

How do I watch these? Right now I'm getting the following error

β ‹ Update webpack configuration/paths/webpack/node_modules/cra-build-watch/scripts/index.js:46
config.entry = config.entry.filter(fileName => !fileName.match(/webpackHotDevClient/));

TypeError: config.entry.filter is not a function

3.0.0 stuck on "Clear destination folder"

I'm using CRA application with react-scripts version 3.2.0.
cra-build-watch version 3.0.0.
When I execute npm run watch it do "Update webpack configuration" and "Clear destination folder" steps and then just do nothing. build folder is empty after running watch.
What I doing wrong?
Thank you!
image

"--after-rebuild-hook" runs before "--after-initial-build-hook"

  • is this issue currently blocking your project? (yes/no): No
  • is this issue affecting a production system? (yes/no): No

Context

  • node version: v14.0.0
  • module version with issue: 6.3.0
  • last module version without issue: unknown
  • environment (e.g. node, browser, native): macOS BigSur
  • used with (e.g. hapi application, another framework, standalone, ...): CRA
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

I added the initial and rebuild hooks as follows:

  "scripts": {
      "hotbuild": "cra-build-watch -v -b webapp/myapp --after-initial-build-hook 'config/inital.sh -d webapp/myapp -w web.xml' --after-rebuild-hook 'config/rebuild.sh",
     ...
 }

What was the result you got?

βœ” after rebuild hook: Rebuild complete. [OK]

βœ” after initial build hook: Initial build. Complete. [OK]

What result did you expect?

On the initial build, I should only see the "after initial build hook" and should never see the "after rebuild hook".
On subsequent builds, I should only see the "after rebuild hook".

Support for CRA 3.0.0?

EDIT - I get the same error with react-scripts v2.1.8 I am guessing there is some dependency in my package.json your watch script doesnt like? Adding package.json as well:

{
        "name": "vast-ui-2",
        "version": "0.1.0",
        "private": true,
        "dependencies": {
                "@material-ui/core": "^3.9.3",
                "@material-ui/icons": "^3.0.2",
                "@material-ui/styles": "latest",
                "autoprefixer": "7.1.6",
                "awesome-debounce-promise": "^2.1.0",
                "axios": "^0.18.0",
                "babel-eslint": "^10.0.1",
                "case-sensitive-paths-webpack-plugin": "2.1.1",
                "classnames": "^2.2.6",
                "css-loader": "0.28.7",
                "date-fns": "^1.30.1",
                "debounce": "^1.2.0",
                "events": "latest",
                "fs-extra": "3.0.1",
                "history": "^4.9.0",
                "is-ip": "^3.0.0",
                "jquery": "^3.3.1",
                "notistack": "^0.4.3",
                "promise": "8.0.1",
                "prop-types": "^15.7.2",
                "react": "^16.8.6",
                "react-broadcast": "^0.6.1",
                "react-dev-utils": "^5.0.1",
                "react-dom": "^16.8.6",
                "react-frame": "latest",
                "react-json-view": "^1.19.1",
                "react-router-bootstrap": "latest",
                "react-router-dom": "^5.0.0",
                "react-scripts": "2.1.8",
                "react-swipeable-views": "^0.13.1",
                "react-table": "^6.9.2",
                "recompose": "^0.26.0",
                "resolve": "1.6.0",
                "style-loader": "0.19.0",
                "styled-components": "^4.2.0",
                "url-loader": "0.6.2"
        },
        "devDependencies": {
                "copy-webpack-plugin": "^4.6.0",
                "cra-build-watch": "^1.4.1",
                "prettier": "1.17.1",
                "react-dev-utils": "^7.0.1"
        },
        "scripts": {
                "start": "react-scripts start",
                "test": "react-scripts test",
                "eject": "react-scripts eject",
                "build": "rm -rf ../public/ && react-scripts build && node scripts/copy.js",
                "watch": "cra-build-watch",
                "sass": "node-sass  ./src/styles/scss --output ./public/css/"
        },
        "eslintConfig": {
                "extends": "react-app"
        },
        "browserslist": {
                "production": [
                        ">0.2%",
                        "not dead",
                        "not op_mini all"
                ],
                "development": [
                        "last 1 chrome version",
                        "last 1 firefox version",
                        "last 1 safari version"
                ]
        }
}

When building I get the following output:

npm run watch --react-scripts-version 3.0.0 --verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli   '/usr/bin/npm',
npm verb cli   'run',
npm verb cli   'watch',
npm verb cli   '--react-scripts-version',
npm verb cli   '3.0.0',
npm verb cli   '--verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'prewatch', 'watch', 'postwatch' ]
npm info lifecycle [email protected]~prewatch: [email protected]
npm info lifecycle [email protected]~watch: [email protected]

> [email protected] watch /home/user/workspace/vast2/vast-ui
> cra-build-watch "3.0.0"


βœ” Update webpack configuration
βœ” Clear destination folder
(node:58237) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
(node:58237) DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead
Error: Plugin could not be registered at 'html-webpack-plugin-before-html-processing'. Hook was not found.
BREAKING CHANGE: There need to exist a hook at 'this.hooks'. To create a compatibility layer for this hook, hook into 'this._pluginCompat'.
    at Compilation.plugin (/home/user/workspace/vast2/vast-ui/node_modules/tapable/lib/Tapable.js:69:9)
    at Compilation.deprecated [as plugin] (internal/util.js:47:15)
    at compiler.plugin.compilation (/home/user/workspace/vast2/vast-ui/node_modules/react-dev-utils/InterpolateHtmlPlugin.js:26:19)
    at SyncHook.eval [as call] (eval at create (/home/user/workspace/vast2/vast-ui/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
    at SyncHook.lazyCompileHook (/home/user/workspace/vast2/vast-ui/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.newCompilation (/home/user/workspace/vast2/vast-ui/node_modules/webpack/lib/Compiler.js:581:26)
    at hooks.beforeCompile.callAsync.err (/home/user/workspace/vast2/vast-ui/node_modules/webpack/lib/Compiler.js:617:29)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/user/workspace/vast2/vast-ui/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/user/workspace/vast2/vast-ui/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.compile (/home/user/workspace/vast2/vast-ui/node_modules/webpack/lib/Compiler.js:612:28)
    at compiler.hooks.watchRun.callAsync.err (/home/user/workspace/vast2/vast-ui/node_modules/webpack/lib/Watching.js:76:18)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/user/workspace/vast2/vast-ui/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at AsyncSeriesHook.lazyCompileHook (/home/use/workspace/vast2/vast-ui/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._go (/home/user/workspace/vast2/vast-ui/node_modules/webpack/lib/Watching.js:40:32)
    at Watching.compiler.readRecords.err (/home/user/workspace/vast2/vast-ui/node_modules/webpack/lib/Watching.js:32:9)
    at Compiler.readRecords (/home/user/workspace/vast2/vast-ui/node_modules/webpack/lib/Compiler.js:479:11)
npm verb lifecycle [email protected]~watch: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~watch: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/user/workspace/vast2/vast-ui/node_modules/.bin:/home/user/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
npm verb lifecycle [email protected]~watch: CWD: /home/user/workspace/vast2/vast-ui
npm info lifecycle [email protected]~watch: Failed to exec watch script
npm verb stack Error: [email protected] watch: `cra-build-watch "3.0.0"`
npm verb stack Exit status 1
npm verb stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
npm verb stack     at emitTwo (events.js:126:13)
npm verb stack     at EventEmitter.emit (events.js:214:7)
npm verb stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
npm verb stack     at emitTwo (events.js:126:13)
npm verb stack     at ChildProcess.emit (events.js:214:7)
npm verb stack     at maybeClose (internal/child_process.js:925:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
npm verb pkgid [email protected]
npm verb cwd /home/users/workspace/vast2/vast-ui
npm verb Linux 4.4.0-97-generic
npm verb argv "/usr/bin/node" "/usr/bin/npm" "run" "watch" "--react-scripts-version" "3.0.0" "--verbose"
npm verb node v8.11.3
npm verb npm  v5.6.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] watch: `cra-build-watch "3.0.0"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 1, true ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.