Molunerfinn / vue-koa-demo

:beginner:A simple full stack demo(CSR & SSR & Docker Support) written by Vue2 & Koa2(Koa1 verson also completed)
MIT License
756 stars 166 forks source link

Use babel for server dev #9

Closed gengjiawen closed 7 years ago

gengjiawen commented 7 years ago

Is is okay to use babel for server dev, I can send a pr.

gengjiawen commented 7 years ago

Inspired by https://github.com/koajs/koa#babel-setup, but not use the same config setup.

Molunerfinn commented 7 years ago

If you're not using node v7.6+, you can use the koa1 version(switch to koa1 branch) . However, you can set the babel config in your project if you want to run it under node v7.6. I think it's ok for now. Thank u all the way :)

gengjiawen commented 7 years ago

I am using node v7.6+. But I also want to use import and export too.

Molunerfinn commented 7 years ago

Aha, that's a good reason. Welcome to send a pr. By the way, I want to use only one node process to run the project in dev mode, I finished it. However it's not so firendly for debugging as restarting the koa server, webpack need to rebuild files too. May be you have some ideas? If you are interested in it, you can look this comment in my blog. Thx :)

gengjiawen commented 7 years ago

I have a solution for auto restart koa server, not sure it's you wanted. When I got time, I will send you a pr.

Molunerfinn commented 7 years ago

Ah, I also finished the auto restart. However when restarting koa server, the webpack neet to rebuild files too. I want to restart the koa server but do not rebuild files. You can send a pr any time if you got time. Thanks a lot ~! :+1:

gengjiawen commented 7 years ago

I am using nodemon to restart the server, which may not be as efficient as webpack.

Molunerfinn commented 7 years ago

I use it too. But you neet to run npm run dev to start the webpack serve, and node app.js or nodemon app.js to start the koa serve. I finished just using node app.js or nodemon app.js to start both webpack & koa serve. As you can see, webpack serve is a express serve, so I can change it to koa serve. Maybe It's stupid haha :)

gengjiawen commented 7 years ago

I don't quite follow you. Do you want to start npm run dev and nodemon app.js the same time ? If that is your case, you can use concurrently.

Molunerfinn commented 7 years ago

Yep, I just use one koa serve to serve the backend api & webpack. concurrently is a solution but not what I want. Anyway, thank u ~ :)

dxcqcv commented 7 years ago

hi, I have a question for those changed, if I wanna use app.js in production env, so I need compile app.js to require version using babel ? if so, not convenience.

Molunerfinn commented 7 years ago

You don't need to compile app.js to a require version. Just using the server-entry.js is OK.

dxcqcv commented 7 years ago

It's OK for development, but that will be a performance problem on production.

Molunerfinn commented 7 years ago

Yep, so it depends on you. However, this project is a small DEMO, try some sepecial I think that is OK~ And in the future, ES6 modules will be available in Node.js. We will see~

gengjiawen commented 7 years ago

For production build, we may need to use change build like https://github.com/babel/example-node-server#getting-ready-for-production-use.