Reputation: 23945
I've been following along the Angular "tour of heroes" tutorial and thought it was a good idea to use webpack along with it.
Locally the application is compiling fine and running without a problem.
The repository is hosted on Visual Studio TeamServices and upon a commit a build is triggered. The build seems to be running fine as well:
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
[email protected] D:\home\site\wwwroot
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
`-- [email protected]
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN optional Skipping failed optional dependency /karma/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN [email protected] No repository field.
Finished successfully.
However, when I run the app I receive the following error in the protocol stream:
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)
According to https://github.com/webpack/webpack/issues/368 the files might be loaded in the incorrect order, but the this would mean it should fail locally too, which it doesn't.
This is my 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'
})
]
}
And the 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)
}
})
]
});
What am I doing wrong? If you need the build definition as well, I'll be happy to edit it in.
Upvotes: 2
Views: 879
Reputation: 23945
It has taken some time, but finally the penny dropped.
There were several issues with my deployment.
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 tried to use npm start
, but since webpack-dev-server was not available and the command itself was the wrong one, the build just failed and everything cascaded down from there.
There for I changed the npm scripts:
"scripts": {
"dev": "webpack-dev-server --inline --progress --port 8080",
"test": "karma start",
"start": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail"
},
Then I started getting several erros about missing dependencies. This made sense after my fourth failed deployment trial, when I realized, that everything under devDependencies: { }
was needed in dependencies: { }
, since this is where npm install --production
is getting its deps from.
At this stage the build was succeeding, but I was getting a 404
. This was rectified, but setting the virtual Path for /
from site\wwwroot
to site\wwwroot\dist
:
Now the website was up and running.
ToDo:
Upvotes: 2