What are differences between SystemJS and Webpack?

前端 未结 3 1341
梦毁少年i
梦毁少年i 2020-11-30 16:38

I\'m creating my first Angular application and I would figure out what is the role of the module loaders. Why we need them? I tried to search and search on Google and I can

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 16:50

    If you go to the SystemJS Github page, you will see the description of the tool:

    Universal dynamic module loader - loads ES6 modules, AMD, CommonJS and global scripts in the browser and NodeJS.

    Because you use modules in TypeScript or ES6, you need a module loader. In the case of SystemJS, the systemjs.config.js allows us to configure the way in which module names are matched with their corresponding files.

    This configuration file (and SystemJS) is necessary if you explicitly use it to import the main module of your application:

    
    

    When using TypeScript, and configuring the compiler to the commonjs module, the compiler creates code that is no longer based on SystemJS. In this example, the typescript compiler config file would appear like this:

    {
      "compilerOptions": {
        "target": "es5",
        "module": "commonjs", // <------
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
      }
    }
    

    Webpack is a flexible module bundler. This means that it goes further and doesn't only handle modules but also provides a way to package your application (concat files, uglify files, ...). It also provides a dev server with load reload for development.

    SystemJS and Webpack are different but with SystemJS, you still have work to do (with Gulp or SystemJS builder for example) to package your Angular2 application for production.

提交回复
热议问题