在弹出后,Webpack构建失败

时间:2017-03-27 17:51:36

标签: angular webpack

我正在尝试修改我的webpack以生成gzip文件,但是没有任何自定义配置它无法构建。

我的方法:

  1. Run ng eject
  2. 删除node_modules
  3. 运行npm install
  4. 运行npm run build
  5. 预期结果: Webpack构建我的模块用于生产

    错误:

    92% chunk asset optimization  
    C:\project_pathnode_modules\source-map\lib\source-node.js:95
              var code = nextLine.substr(0, mapping.generatedColumn -
                                 ^
    
    TypeError: Cannot read property 'substr' of undefined
        at Function.<anonymous> (C:\project_pathnode_modules\source-map\lib\source-node.js:95:30)
        at Array.forEach (native)
        at BasicSourceMapConsumer.SourceMapConsumer_eachMapping [as eachMapping] (C:\project_pathnode_modules\source-map\lib\source-map-consumer.js:155:14)
        at Function.SourceNode_fromStringWithSourceMap [as fromStringWithSourceMap](C:\project_pathnode_modules\source-map\lib\source-node.js:80:24)
        at SourceMapSource.node (C:\project_pathnode_modules\webpack-sources\lib\SourceMapSource.js:42:20)
        at ReplaceSource.node (C:\project_pathnode_modules\webpack-sources\lib\ReplaceSource.js:69:29)
        at CachedSource.node (C:\project_pathnode_modules\webpack-sources\lib\CachedSource.js:12:23)
        at C:\project_pathnode_modules\webpack-sources\lib\ConcatSource.js:40:49
        at Array.map (native)
        at ConcatSource.node (C:\project_pathnode_modules\webpack-sources\lib\ConcatSource.js:39:60)
        at C:\project_pathnode_modules\webpack-sources\lib\ConcatSource.js:40:49
        at Array.map (native)
        at ConcatSource.node (C:\project_pathnode_modules\webpack-sources\lib\ConcatSource.js:39:60)
        at C:\project_pathnode_modules\webpack-sources\lib\ConcatSource.js:40:49
        at Array.map (native)
        at ConcatSource.node (C:\project_pathnode_modules\webpack-sources\lib\ConcatSource.js:39:60)
        at C:\project_pathnode_modules\webpack-sources\lib\ConcatSource.js:40:49
        at Array.map (native)
        at ConcatSource.node (C:\project_pathnode_modules\webpack-sources\lib\ConcatSource.js:39:60)
        at ConcatSource.proto.sourceAndMap (C:\project_pathnode_modules\webpack-sources\lib\SourceAndMapMixin.js:28:18)
        at CachedSource.sourceAndMap (C:\project_pathnode_modules\webpack-sources\lib\CachedSource.js:51:28)
        at Compilation.<anonymous> (C:\project_pathnode_modules\webpack\lib\SourceMapDevToolPlugin.js:57:32)
        at Array.map (native)
        at Compilation.<anonymous> (C:\project_pathnode_modules\webpack\lib\SourceMapDevToolPlugin.js:43:84)
        at Array.forEach (native)
        at Compilation.<anonymous> (C:\project_pathnode_modules\webpack\lib\SourceMapDevToolPlugin.js:42:11)
        at Compilation.applyPlugins1 (C:\project_pathnode_modules\tapable\lib\Tapable.js:75:14)
        at self.applyPluginsAsync.err (C:\project_pathnode_modules\webpack\lib\Compilation.js:630:11)
        at next (C:\project_pathnode_modules\tapable\lib\Tapable.js:138:11)
        at Compilation.<anonymous> (C:\project_pathnode_modules\webpack\lib\ProgressPlugin.js:118:5)
    

    package.json(放入一个pastebin,因为SO太长了:
      package.json

    webpack.config.js(从弹出中未修改):

    const path = require('path');
    const ProgressPlugin = require('webpack/lib/ProgressPlugin');
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    const ExtractTextPlugin = require('extract-text-webpack-plugin');
    const autoprefixer = require('autoprefixer');
    const postcssUrl = require('postcss-url');
    
    const { NoEmitOnErrorsPlugin, LoaderOptionsPlugin } = require('webpack');
    const { GlobCopyWebpackPlugin, BaseHrefWebpackPlugin } = require('@angular/cli/plugins/webpack');
    const { CommonsChunkPlugin } = require('webpack').optimize;
    const { AotPlugin } = require('@ngtools/webpack');
    
    const nodeModules = path.join(process.cwd(), 'node_modules');
    const entryPoints = ["inline","polyfills","sw-register","scripts","styles","vendor","main"];
    const baseHref = undefined;
    const deployUrl = undefined;
    
    
    
    
    module.exports = {
      "devtool": "source-map",
      "resolve": {
        "extensions": [
          ".ts",
          ".js"
        ],
        "modules": [
          "./node_modules"
        ]
      },
      "resolveLoader": {
        "modules": [
          "./node_modules"
        ]
      },
      "entry": {
        "main": [
          "./src\\main.ts"
        ],
        "polyfills": [
          "./src\\polyfills.ts"
        ],
        "scripts": [
          "script-loader!./node_modules\\clappr\\dist\\clappr.min.js",
          "script-loader!./node_modules\\jquery\\dist\\jquery.min.js",
          "script-loader!./node_modules\\chart.js\\dist\\Chart.min.js",
          "script-loader!./node_modules\\peity\\jquery.peity.min.js",
          "script-loader!./node_modules\\jqvmap\\dist\\jquery.vmap.min.js",
          "script-loader!./node_modules\\hammerjs\\hammer.min.js",
          "script-loader!./node_modules\\moment\\min\\moment.min.js",
          "script-loader!./node_modules\\fullcalendar\\dist\\fullcalendar.min.js",
          "script-loader!./node_modules\\jquery-fullscreen-plugin\\jquery.fullscreen-min.js"
        ],
        "styles": [
          "./node_modules\\quill\\dist\\quill.core.css",
          "./node_modules\\quill\\dist\\quill.bubble.css",
          "./node_modules\\quill\\dist\\quill.snow.css",
          "./node_modules\\font-awesome\\css\\font-awesome.css",
          "./node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css",
          "./node_modules\\weathericons\\css\\weather-icons.css",
          "./node_modules\\weathericons\\css\\weather-icons-wind.css",
          "./node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css",
          "./node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css",
          "./node_modules\\@swimlane\\ngx-datatable\\release\\material.css",
          "./node_modules\\fullcalendar\\dist\\fullcalendar.css",
          "./node_modules\\github-markdown-css\\github-markdown.css",
          "./src\\styles.scss"
        ]
      },
      "output": {
        "path": path.join(process.cwd(), "dist"),
        "filename": "[name].bundle.js",
        "chunkFilename": "[id].chunk.js"
      },
      "module": {
        "rules": [
          {
            "enforce": "pre",
            "test": /\.js$/,
            "loader": "source-map-loader",
            "exclude": [
              /\/node_modules\//
            ]
          },
          {
            "test": /\.json$/,
            "loader": "json-loader"
          },
          {
            "test": /\.html$/,
            "loader": "raw-loader"
          },
          {
            "test": /\.(eot|svg)$/,
            "loader": "file-loader?name=[name].[hash:20].[ext]"
          },
          {
            "test": /\.(jpg|png|gif|otf|ttf|woff|woff2|cur|ani)$/,
            "loader": "url-loader?name=[name].[hash:20].[ext]&limit=10000"
          },
          {
            "exclude": [
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.core.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.bubble.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.snow.css"),
              path.join(process.cwd(), "node_modules\\font-awesome\\css\\font-awesome.css"),
              path.join(process.cwd(), "node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons-wind.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\material.css"),
              path.join(process.cwd(), "node_modules\\fullcalendar\\dist\\fullcalendar.css"),
              path.join(process.cwd(), "node_modules\\github-markdown-css\\github-markdown.css"),
              path.join(process.cwd(), "src\\styles.scss")
            ],
            "test": /\.css$/,
            "loaders": [
              "exports-loader?module.exports.toString()",
              "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
              "postcss-loader"
            ]
          },
          {
            "exclude": [
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.core.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.bubble.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.snow.css"),
              path.join(process.cwd(), "node_modules\\font-awesome\\css\\font-awesome.css"),
              path.join(process.cwd(), "node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons-wind.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\material.css"),
              path.join(process.cwd(), "node_modules\\fullcalendar\\dist\\fullcalendar.css"),
              path.join(process.cwd(), "node_modules\\github-markdown-css\\github-markdown.css"),
              path.join(process.cwd(), "src\\styles.scss")
            ],
            "test": /\.scss$|\.sass$/,
            "loaders": [
              "exports-loader?module.exports.toString()",
              "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
              "postcss-loader",
              "sass-loader"
            ]
          },
          {
            "exclude": [
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.core.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.bubble.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.snow.css"),
              path.join(process.cwd(), "node_modules\\font-awesome\\css\\font-awesome.css"),
              path.join(process.cwd(), "node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons-wind.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\material.css"),
              path.join(process.cwd(), "node_modules\\fullcalendar\\dist\\fullcalendar.css"),
              path.join(process.cwd(), "node_modules\\github-markdown-css\\github-markdown.css"),
              path.join(process.cwd(), "src\\styles.scss")
            ],
            "test": /\.less$/,
            "loaders": [
              "exports-loader?module.exports.toString()",
              "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
              "postcss-loader",
              "less-loader"
            ]
          },
          {
            "exclude": [
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.core.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.bubble.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.snow.css"),
              path.join(process.cwd(), "node_modules\\font-awesome\\css\\font-awesome.css"),
              path.join(process.cwd(), "node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons-wind.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\material.css"),
              path.join(process.cwd(), "node_modules\\fullcalendar\\dist\\fullcalendar.css"),
              path.join(process.cwd(), "node_modules\\github-markdown-css\\github-markdown.css"),
              path.join(process.cwd(), "src\\styles.scss")
            ],
            "test": /\.styl$/,
            "loaders": [
              "exports-loader?module.exports.toString()",
              "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
              "postcss-loader",
              "stylus-loader?{\"sourceMap\":false,\"paths\":[]}"
            ]
          },
          {
            "include": [
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.core.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.bubble.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.snow.css"),
              path.join(process.cwd(), "node_modules\\font-awesome\\css\\font-awesome.css"),
              path.join(process.cwd(), "node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons-wind.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\material.css"),
              path.join(process.cwd(), "node_modules\\fullcalendar\\dist\\fullcalendar.css"),
              path.join(process.cwd(), "node_modules\\github-markdown-css\\github-markdown.css"),
              path.join(process.cwd(), "src\\styles.scss")
            ],
            "test": /\.css$/,
            "loaders": ExtractTextPlugin.extract({
      "use": [
        "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
        "postcss-loader"
      ],
      "fallback": "style-loader",
      "publicPath": ""
    })
          },
          {
            "include": [
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.core.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.bubble.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.snow.css"),
              path.join(process.cwd(), "node_modules\\font-awesome\\css\\font-awesome.css"),
              path.join(process.cwd(), "node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons-wind.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\material.css"),
              path.join(process.cwd(), "node_modules\\fullcalendar\\dist\\fullcalendar.css"),
              path.join(process.cwd(), "node_modules\\github-markdown-css\\github-markdown.css"),
              path.join(process.cwd(), "src\\styles.scss")
            ],
            "test": /\.scss$|\.sass$/,
            "loaders": ExtractTextPlugin.extract({
      "use": [
        "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
        "postcss-loader",
        "sass-loader"
      ],
      "fallback": "style-loader",
      "publicPath": ""
    })
          },
          {
            "include": [
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.core.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.bubble.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.snow.css"),
              path.join(process.cwd(), "node_modules\\font-awesome\\css\\font-awesome.css"),
              path.join(process.cwd(), "node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons-wind.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\material.css"),
              path.join(process.cwd(), "node_modules\\fullcalendar\\dist\\fullcalendar.css"),
              path.join(process.cwd(), "node_modules\\github-markdown-css\\github-markdown.css"),
              path.join(process.cwd(), "src\\styles.scss")
            ],
            "test": /\.less$/,
            "loaders": ExtractTextPlugin.extract({
      "use": [
        "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
        "postcss-loader",
        "less-loader"
      ],
      "fallback": "style-loader",
      "publicPath": ""
    })
          },
          {
            "include": [
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.core.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.bubble.css"),
              path.join(process.cwd(), "node_modules\\quill\\dist\\quill.snow.css"),
              path.join(process.cwd(), "node_modules\\font-awesome\\css\\font-awesome.css"),
              path.join(process.cwd(), "node_modules\\material-design-icon-fonts\\iconfont\\material-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons.css"),
              path.join(process.cwd(), "node_modules\\weathericons\\css\\weather-icons-wind.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\assets\\icons.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\datatable.css"),
              path.join(process.cwd(), "node_modules\\@swimlane\\ngx-datatable\\release\\material.css"),
              path.join(process.cwd(), "node_modules\\fullcalendar\\dist\\fullcalendar.css"),
              path.join(process.cwd(), "node_modules\\github-markdown-css\\github-markdown.css"),
              path.join(process.cwd(), "src\\styles.scss")
            ],
            "test": /\.styl$/,
            "loaders": ExtractTextPlugin.extract({
      "use": [
        "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
        "postcss-loader",
        "stylus-loader?{\"sourceMap\":false,\"paths\":[]}"
      ],
      "fallback": "style-loader",
      "publicPath": ""
    })
          },
          {
            "test": /\.ts$/,
            "loader": "@ngtools/webpack"
          }
        ]
      },
      "plugins": [
        new NoEmitOnErrorsPlugin(),
        new GlobCopyWebpackPlugin({
          "patterns": [
            "assets",
            "favicon.ico"
          ],
          "globOptions": {
            "cwd": "C:\\Users\\Moshe\\Desktop\\Matrix-ng4\\src",
            "dot": true,
            "ignore": "**/.gitkeep"
          }
        }),
        new ProgressPlugin(),
        new HtmlWebpackPlugin({
          "template": "./src\\index.html",
          "filename": "./index.html",
          "hash": false,
          "inject": true,
          "compile": true,
          "favicon": false,
          "minify": false,
          "cache": true,
          "showErrors": true,
          "chunks": "all",
          "excludeChunks": [],
          "title": "Webpack App",
          "xhtml": true,
          "chunksSortMode": function sort(left, right) {
            let leftIndex = entryPoints.indexOf(left.names[0]);
            let rightindex = entryPoints.indexOf(right.names[0]);
            if (leftIndex > rightindex) {
                return 1;
            }
            else if (leftIndex < rightindex) {
                return -1;
            }
            else {
                return 0;
            }
        }
        }),
        new BaseHrefWebpackPlugin({}),
        new CommonsChunkPlugin({
          "name": "inline",
          "minChunks": null
        }),
        new CommonsChunkPlugin({
          "name": "vendor",
          "minChunks": (module) => module.resource && module.resource.startsWith(nodeModules),
          "chunks": [
            "main"
          ]
        }),
        new ExtractTextPlugin({
          "filename": "[name].bundle.css",
          "disable": true
        }),
        new LoaderOptionsPlugin({
          "sourceMap": true,
          "options": {
            "postcss": [
              autoprefixer(),
              postcssUrl({"url": (URL) => {
                // Only convert absolute URLs, which CSS-Loader won't process into require().
                if (!URL.startsWith('/')) {
                    return URL;
                }
                // Join together base-href, deploy-url and the original URL.
                // Also dedupe multiple slashes into single ones.
                return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/');
            }})
            ],
            "sassLoader": {
              "sourceMap": false,
              "includePaths": []
            },
            "lessLoader": {
              "sourceMap": false
            },
            "context": ""
          }
        }),
        new AotPlugin({
          "mainPath": "main.ts",
          "hostReplacementPaths": {
            "environments\\environment.ts": "environments\\environment.ts"
          },
          "exclude": [],
          "tsConfigPath": "src\\tsconfig.app.json",
          "skipCodeGeneration": true
        })
      ],
      "node": {
        "fs": "empty",
        "global": true,
        "crypto": "empty",
        "tls": "empty",
        "net": "empty",
        "process": true,
        "module": false,
        "clearImmediate": false,
        "setImmediate": false
      }
    };
    

    我试图将提议的解决方案here纳入其中无济于事。

0 个答案:

没有答案