We're developing an Office Addin application with Nodejs server using typescript. In development, everything is fine. however, when we wanna take a build of the application on production mode and deploy its ./dist folder to azure, some js libraries are missing used in HTML files. I observed that the hashed names for js files are different than the hashed names in referenced HTML.
When we take a build in development mode like "npm run build:development" and deploy, there is no problem. the application works normally with no missing files. Why production mode build process gives different hashed file name for js as the development mode build process gives proper names?
/* eslint-disable no-undef */
const path = require("path");
const devCerts = require("office-addin-dev-certs");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const urlDev = "https://localhost:3000/";
const urlProd = "https://xxx.z13.web.core.windows.net/"; // CHANGE THIS TO YOUR PRODUCTION DEPLOYMENT LOCATION
async function getHttpsOptions() {
const httpsOptions = await devCerts.getHttpsServerOptions();
return { cacert: httpsOptions.ca, key: httpsOptions.key, cert: httpsOptions.cert };
}
module.exports = async (env, options) => {
const dev = options.mode === "development";
const config = {
devtool: "source-map",
entry: {
polyfill: ["core-js/stable", "regenerator-runtime/runtime"],
taskpane: "./src/taskpane/taskpane.ts",
commands: "./src/commands/commands.ts",
pms: "./src/taskpane/pms.ts",
tocpane: "./src/taskpane/tocpane.ts",
modelpane: "./src/taskpane/modelpane.ts",
dialog: "./src/dialogs/dialog.ts",
},
output: {
devtoolModuleFilenameTemplate: "webpack:///[resource-path]?[loaders]",
clean: true,
},
resolve: {
extensions: [".ts", ".tsx", ".html", ".js"],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-typescript"],
},
},
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: "ts-loader",
},
{
test: /\.html$/,
exclude: /node_modules/,
use: "html-loader",
},
{
test: /\.(png|jpg|jpeg|gif|ico)$/,
type: "asset/resource",
generator: {
filename: "assets/images/[name][ext][query]",
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
filename: "taskpane.html",
template: "./src/taskpane/taskpane.html",
chunks: ["polyfill", "taskpane"],
}),
new HtmlWebpackPlugin({
filename: "pms.html",
template: "./src/taskpane/pms.html",
chunks: ["polyfill", "pms"],
}),
new HtmlWebpackPlugin({
filename: "tocpane.html",
template: "./src/taskpane/tocpane.html",
chunks: ["polyfill", "tocpane"],
}),
new HtmlWebpackPlugin({
filename: "modelpane.html",
template: "./src/taskpane/modelpane.html",
chunks: ["polyfill", "modelpane"],
}),
new HtmlWebpackPlugin({
filename: "dialog.html",
template: "./src/dialogs/dialog.html",
chunks: ["polyfill", "dialog"],
}),
new CopyWebpackPlugin({
patterns: [
{
from: "schema/*",
to: "schema/[name][ext][query]",
},
{
from: "assets/images/*",
to: "assets/images/[name][ext][query]",
},
{
from: "assets/css/jstree/default/*",
to: "assets/css/jstree/default/[name][ext][query]",
},
{
from: "manifest*.xml",
to: "[name]" + "[ext]",
transform(content) {
if (dev) {
return content;
} else {
return content.toString().replace(new RegExp(urlDev, "g"), urlProd);
}
},
},
],
}),
new HtmlWebpackPlugin({
filename: "commands.html",
template: "./src/commands/commands.html",
chunks: ["polyfill", "commands"],
}),
],
devServer: {
headers: {
"Access-Control-Allow-Origin": "*",
},
https: env.WEBPACK_BUILD || options.https !== undefined ? options.https : await getHttpsOptions(),
port: process.env.npm_package_config_dev_server_port || 3000,
},
};
return config;
};
By default when a new solution is created by using the Yeoman generator you can find the following commands in the
package.jsonfile:As you can see
webpackis used in both cases for building the solution. In that case you need to check out thewebpack.config.jsfile where all instructions for building the solution by webpack is located. You might have noticed the parameter passed to webpack to instruct how to build it. Themodeparameter can be set toproductionordevelopment. In the config file all these two parameters are used to configure/bundle files. See https://webpack.js.org/concepts/ for more information how to configure webpack.