webpack2 + babel很慢

时间:2017-03-25 15:48:27

标签: webpack ecmascript-6 babeljs webpack-2

我正在使用webpack和babel从ES6或ES5编译一些小代码。 它不加载任何外部模块,它只是1 kb的javascript。

问题是编译需要50秒,这很疯狂。

有没有办法加速这个?

我的webpack.config.js:

//const glob = require("glob");
const path = require("path");
const webpack = require("webpack");

//const entries = glob.sync("./src/*.js");
const entriesDict = {};

// entries.forEach(function (value) {
//     var k = path.basename(value);
//     console.log("Found: " + k + " => " + value);
//     entriesDict[k] = value;
// });

entriesDict['Master.js'] = './src/Master.js';

module.exports = {
    entry: entriesDict,

    output: {
        filename: "[name]",
        path: path.resolve(__dirname, "dist"),
        libraryTarget: "commonjs2"
    },

    devtool: "eval",

    module: {
        rules: [
            {
                test: /\.jsx?$/,
                use: [
                    "babel-loader?cacheDirectory=true",
                ],
                exclude: /(node_modules|bower_components)/,
                include: path.resolve(__dirname, "src")
            },
        ],
    },

    resolve : {
        unsafeCache: true
    },

    plugins: [],
};

我的.babelrc文件:

{
    "presets": [
        ["es2015", {"modules": false}],
        "stage-2",
        "react"
    ],
    "plugins": [
    ]
}

以下是webpack制作的个人资料:

{
  "errors": [],
  "warnings": [],
  "version": "2.3.1",
  "hash": "5c28c7fccf2048360fef",
  "time": 40779,
  "publicPath": "",
  "assetsByChunkName": {
    "Master.js": "Master.js"
  },
  "assets": [
    {
      "name": "Master.js",
      "size": 3573,
      "chunks": [
        0
      ],
      "chunkNames": [
        "Master.js"
      ],
      "emitted": true
    }
  ],
  "entrypoints": {
    "Master.js": {
      "chunks": [
        0
      ],
      "assets": [
        "Master.js"
      ]
    }
  },
  "chunks": [
    {
      "id": 0,
      "rendered": true,
      "initial": true,
      "entry": true,
      "extraAsync": false,
      "size": 551,
      "names": [
        "Master.js"
      ],
      "files": [
        "Master.js"
      ],
      "hash": "1b51d9c187096fb160f0",
      "parents": [],
      "modules": [
        {
          "id": 0,
          "identifier": "/mnt/viasmb/LAMBDAS/node_modules/babel-loader/lib/index.js?cacheDirectory=true!/mnt/viasmb/LAMBDAS/src/Master.js",
          "name": "./src/Master.js",
          "index": 0,
          "index2": 0,
          "size": 551,
          "cacheable": true,
          "built": true,
          "optional": false,
          "prefetched": false,
          "chunks": [
            0
          ],
          "assets": [],
          "issuer": null,
          "issuerId": null,
          "issuerName": null,
          "profile": {
            "factory": 34,
            "building": 40714
          },
          "failed": false,
          "errors": 0,
          "warnings": 0,
          "reasons": [],
          "usedExports": true,
          "providedExports": [
            "handler"
          ],
          "depth": 0,
          "source": "//import {run as actLogin} from \"./Master/Login.js\";\n//import {run as actLogout} from \"./Master/Logout.js\";\n\nexport function handler(event, context, callback) {\n    try {\n        switch (event.action) {\n            case 'login':\n                callback(null, actLogin(event));\n            case 'logout':\n                callback(null, actLogout(event));\n            default:\n                callback(new Error(\"Invalid action: \" + event.action));\n        }\n    } catch (e) {\n        console.log(\"Exception catched: \", e);\n        callback(e);\n    }\n}"
        }
      ],
      "filteredModules": 0,
      "origins": [
        {
          "moduleId": 0,
          "module": "/mnt/viasmb/LAMBDAS/node_modules/babel-loader/lib/index.js?cacheDirectory=true!/mnt/viasmb/LAMBDAS/src/Master.js",
          "moduleIdentifier": "/mnt/viasmb/LAMBDAS/node_modules/babel-loader/lib/index.js?cacheDirectory=true!/mnt/viasmb/LAMBDAS/src/Master.js",
          "moduleName": "./src/Master.js",
          "loc": "",
          "name": "Master.js",
          "reasons": []
        }
      ]
    }
  ],
  "modules": [
    {
      "id": 0,
      "identifier": "/mnt/viasmb/LAMBDAS/node_modules/babel-loader/lib/index.js?cacheDirectory=true!/mnt/viasmb/LAMBDAS/src/Master.js",
      "name": "./src/Master.js",
      "index": 0,
      "index2": 0,
      "size": 551,
      "cacheable": true,
      "built": true,
      "optional": false,
      "prefetched": false,
      "chunks": [
        0
      ],
      "assets": [],
      "issuer": null,
      "issuerId": null,
      "issuerName": null,
      "profile": {
        "factory": 34,
        "building": 40714
      },
      "failed": false,
      "errors": 0,
      "warnings": 0,
      "reasons": [],
      "usedExports": true,
      "providedExports": [
        "handler"
      ],
      "depth": 0,
      "source": "//import {run as actLogin} from \"./Master/Login.js\";\n//import {run as actLogout} from \"./Master/Logout.js\";\n\nexport function handler(event, context, callback) {\n    try {\n        switch (event.action) {\n            case 'login':\n                callback(null, actLogin(event));\n            case 'logout':\n                callback(null, actLogout(event));\n            default:\n                callback(new Error(\"Invalid action: \" + event.action));\n        }\n    } catch (e) {\n        console.log(\"Exception catched: \", e);\n        callback(e);\n    }\n}"
    }
  ],
  "filteredModules": 0,
  "children": []
}

这是我试图编译的Master.js脚本:

export function handler(event, context, callback) {
    try {
        switch (event.action) {
            case 'login':
                callback(null, actLogin(event));
            case 'logout':
                callback(null, actLogout(event));
            default:
                callback(new Error("Invalid action: " + event.action));
        }
    } catch (e) {
        console.log("Exception catched: ", e);
        callback(e);
    }
}

谢谢,

0 个答案:

没有答案