Comments (6)
Try doing something along the following lines:
const { appendWebpackPlugin } = require('@rescripts/utilities')
const webpack = require('webpack');
module.exports = [
{
devServer: () => ({
before(app) {
apiMocker(app, path.resolve('./mocker/index.js'),
{
proxy: {
'/repos/*': 'https://api.github.com/',
'/:owner/:repo/raw/:ref/*': 'http://127.0.0.1:2018'
},
changeHost: true,
}),
},
},
},
['use-babel-config', '.babelrc'],
appendWebpackPlugin(
new webpack.DefinePlugin({
'process.env': {
LOCALE: JSON.stringify('zh-CN'),
},
}),
)
];
Let me know how this goes 👍
from rescripts.
Thank you ! I works!
But still have a little problem:
when i add just an empty devServer ,the cra project can run , but has an exception on startup :
module.exports = [ { devServer: () => ({ }) }, ['use-babel-config', '.babelrc'] , appendWebpackPlugin( new webpack.DefinePlugin({ 'process.env': { LOCALE: JSON.stringify('zh-CN'), }, }), ) ];
× 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59) × 「wds」: Exception on "GET /sockjs-node" in filter "welcome_screen": Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:257:14) at Socket.Writable.write (_stream_writable.js:306:5) at Socket.Writable.end (_stream_writable.js:617:10) at Socket.end (net.js:580:31) at App.exports.GenericApp.GenericApp.handle_error (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:152:15) at execute_request (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:36:28) at IncomingMessage.req.next_filter (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:105:18) at Listener.webjs_handler (D:\Projects\shinein\node_modules\sockjs\lib\webjs.js:107:13) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:150:12) at Listener.handler (D:\Projects\shinein\node_modules\sockjs\lib\sockjs.js:6:59)
from rescripts.
You're overriding the preexisting dev server config with an empty object. That's not a valid CRA dev server config. Hence the error.
from rescripts.
when the config like this , the error is still exist
{ devServer: () => ({ before(app) { apiMocker(app, path.resolve('./mock/index.js'), {}) } }) }
this code may also overrid the preexisting dev server config.
is there any method to get the CRA dev server config
,so i can customize it, merge my
apiMocker ?
from rescripts.
Did you follow the WebPack Dev Server documentation?
from rescripts.
i found the answer in rescripts readme .
CodeA:
devServer: () => ({ before(app) { apiMocker(app, path.resolve('./mock/index.js'), {}) } })
CodeB:
devServer: config => { newConfig = doConfig(config); return config ; }
CodeA means override all devServer config, CodeB means change devServer config.
I should use CodeB .
this is my config ,and it works:
const { appendWebpackPlugin } = require('@rescripts/utilities') const webpack = require('webpack'); const path = require('path'); const apiMocker = require('mocker-api'); module.exports = [ { devServer: config => { defaultBefore = config.before; config.before = (app, server) => { defaultBefore(app, server); apiMocker(app, path.resolve('./mock/index.js'), {}) } return config } }, ['use-babel-config', '.babelrc'] , appendWebpackPlugin( new webpack.DefinePlugin({ 'process.env': { LOCALE: JSON.stringify('zh-CN'), }, }), ) ];
thank you ! @harrysolovay
from rescripts.
Related Issues (20)
- Compatibility with custom react-scripts forks HOT 1
- Show error output for rescript config errors HOT 3
- Global configuration not taken into account HOT 1
- Dev server hangs when trying to add another entry point HOT 4
- react-dev-utils need to be updated HOT 1
- .babelrc.js export function does not work HOT 3
- Adding ".babelrc" breaks typescript support in react HOT 1
- Allow react-scripts v4 without npm warning
- Typescript update to 4.X? HOT 1
- Install the last version of react-dev-utils to fix a vulnerability HOT 2
- No matching version for @rescripts/rescript-use-eslint-config dependency in @rescripts/rescript-env HOT 7
- How do I extend the jest config? HOT 1
- Setting a static name for the files generated by build HOT 2
- Webpack config HOT 4
- PostCSS config not working HOT 1
- [Question] Multiple entry points + shared/common chunks howto example for noobs HOT 1
- Is there any way how to easily change paths? HOT 3
- How to add a devserver before or after hook? HOT 1
- How to get React Fast Refresh to work HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rescripts.