Build this node project using only gulp or webpack

2019-07-29 19:35发布

问题:

My project has this folder structure:

node
|   .gitignore
|   gulpfile.js
|   package.json
|   tsconfig.json
|   webpack.config.js
|   
+---build
|   |   debug.js
|   |   main.js
|   |   
|   +---client
|   |   +---scripts
|   |   |       bundle.js
|   |   |       
|   |   \---views
|   |           index.html
|   |           
|   |               
|   \---server
|       |   constants.js
|       |   server.js
|       |   
|       \---router
|           |   constants.js
|           |   router.js
|           |   
|           \---routes
|                   base.js
|                   index.js
|                   
+---gulp
|   |   constants.js
|   |   
|   \---tasks
|           default.js
|           html.js
|           typescript.js
|           
\---src
    |   main.ts
    |   
    +---client
    |   +---app
    |   |   |   app.tsx
    |   |   |   
    |   |   \---components
    |   |           hello.tsx
    |   |           
    |   \---views
    |           index.html
    |               
    \---server
        |   constants.ts
        |   server.ts
        |   
        \---router
            |   constants.ts
            |   router.ts
            |   
            \---routes
                    base.ts
                    index.ts

Gulp is used to copy HTML and compile TypeScript in build folder maintaining folder structure. But I didn't found how to also bundle front-end code and node dependencies in order to make these avaiable in build/client. After some suggestion and research I used Webpack to create bundle.js.

Now I've the expected result but I wonder if there is a way to only Gulp or Webpack, in order to simplify the build process.

回答1:

I wonder if there is a way to only Gulp or Webpack

These are different tools.

  • Gulp: Task runners. Runs code segments
  • Webpack: Module bundler. Bundles code in a manner that can be used in the browser.

If you want a bundler (which you do) gulp will not suffice.