部署到Azure后未定义webpackJsonp

时间:2017-06-13 20:05:28

标签: angular azure typescript webpack azure-devops

我一直在跟随Angular“英雄之旅”教程,并认为使用webpack是一个好主意。

本地应用程序编译正常并且运行没有问题。

存储库托管在Visual Studio TeamServices上,并在提交时触发构建。 构建似乎运行良好:

Command: deploy.cmd
Handling node.js deployment.
KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
Copying file: 'package.json'
Copying file: 'tsconfig.json'
Looking for app.js/server.js under site root.
Node.js versions available on the platform are: 0.6.20, 0.8.2, 0.8.19, 0.8.26, 0.8.27, 0.8.28, 0.10.5, 0.10.18, 0.10.21, 0.10.24, 0.10.26, 0.10.28, 0.10.29, 0.10.31, 0.10.32, 0.10.40, 0.12.0, 0.12.2, 0.12.3, 0.12.6, 4.0.0, 4.1.0, 4.1.2, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.3.0, 4.3.2, 4.4.0, 4.4.1, 4.4.6, 4.4.7, 4.5.0, 4.6.0, 4.6.1, 5.0.0, 5.1.1, 5.3.0, 5.4.0, 5.5.0, 5.6.0, 5.7.0, 5.7.1, 5.8.0, 5.9.1, 6.0.0, 6.1.0, 6.2.2, 6.3.0, 6.5.0, 6.6.0, 6.7.0, 6.9.0, 6.9.1, 6.9.2, 6.9.4, 6.9.5, 6.10.0, 7.0.0, 7.1.0, 7.2.0, 7.3.0, 7.4.0, 7.5.0, 7.6.0, 7.7.4, 7.10.0, 8.0.0.
Selected node.js version 6.1.0. Use package.json file to choose a different version.
Selected npm version 3.8.6
Updating iisnode.yml at D:\home\site\wwwroot\iisnode.yml
Invalid start-up command "webpack-dev-server --inline --progress --port 8080" in package.json. Please use the format "node <script relative path>".
Missing server.js/app.js files, web.config is not generated
angulartemplate@1.0.0 D:\home\site\wwwroot
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
`-- typescript@2.3.4 
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.1.2

npm WARN optional Skipping failed optional dependency /karma/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.1.2
npm WARN angulartemplate@1.0.0 No repository field.
Finished successfully.

但是,当我运行应用程序时,我在协议流中收到以下错误:

ReferenceError: webpackJsonp is not defined
at Object.<anonymous> (D:\home\site\wwwroot\dist\app.js:1:63)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (D:\Program Files (x86)\iisnode\interceptor.js:459:1)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)

根据https://github.com/webpack/webpack/issues/368,文件可能以不正确的顺序加载,但这意味着它也应该在本地失败,但事实并非如此。

这是我的webpack.common.config:

module.exports = {
    entry: {
        "polyfills": "./src/polyfills.ts",
        "vendor": "./src/vendor.ts",
        "app": "./src/main.ts"
    },

    resolve: {
        extensions: [
            ".js", ".ts", ".less", ".scss"
        ],
        modules: [
            'node_modules'
        ]
    },


    module: {
        loaders: [{
               //omitted
            }]
    },

    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            name: ['app', 'vendor', 'polyfills'],
            filename: "[name].js",
            minChunks: "infinity"
        }),

        new HtmlWebpackPlugin({
            template: 'src/index.html'
        })
    ]
}

和webpack.prod.js:

const ENV = process.env.NODE_ENV = process.env.ENV = 'production';

module.exports = webpackMerge(commonConfig, {
  devtool: 'source-map',

  output: {
    path: helpers.root('dist'),
    publicPath: '/',
    filename: '[name].[hash].js',
    chunkFilename: '[id].[hash].chunk.js'
  },

  plugins: [
    new webpack.NoErrorsPlugin(),
    //new webpack.optimize.DedupePlugin(),
    new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618
      mangle: {
        keep_fnames: true
      }
    }),
    new ExtractTextPlugin('[name].[hash].css'),
    new webpack.DefinePlugin({
      'process.env': {
        'ENV': JSON.stringify(ENV)
      }
    })
  ]
});

我做错了什么?如果您还需要构建定义,我将很乐意在其中进行编辑。

1 个答案:

答案 0 :(得分:2)

这花了一些时间,但最后便士掉了下来。

我的部署存在一些问题。

Invalid start-up command "webpack-dev-server --inline --progress --port 8080" in package.json. Please use the format "node <script relative path>". Missing server.js/app.js files, web.config is not generated

Azure尝试使用npm start,但由于webpack-dev-server不可用且命令本身是错误的,因此构建失败并且所有内容都从那里级联。

我改变了npm脚本:

"scripts": {
    "dev": "webpack-dev-server --inline --progress --port 8080",
    "test": "karma start",
    "start": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail"
  },

然后我开始得到几个关于缺少依赖项的错误。在我第四次失败的部署试用之后,当我意识到devDependencies: { }中需要dependencies: { }下的所有内容时,这是有意义的,因为这是npm install --production正在从中获取它的地方。

在这个阶段,构建成功了,但我得到了404。这已得到纠正,但将/的虚拟路径从site\wwwroot设置为site\wwwroot\dist

enter image description here

现在网站已经启动并运行。

TODO:

  • 定义Post Deployment步骤以删除/ node_modules /文件夹,因为我现在使用200Megs的空间用于简单的Hello World应用程序。
相关问题