Shmuel H
01/29/2024, 7:26 PMJay Jetley
01/30/2024, 11:14 AMJay Jetley
01/30/2024, 11:16 AM{
"compilerOptions": {
"outDir": "dist",
"module": "AMD",
"target": "es5",
"moduleResolution":"node",
"sourceMap": false,
"newLine": "LF",
"experimentalDecorators": true,
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "noImplicitUseStrict": true,
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"baseUrl": ".",
"lib": ["es5", "es2015.promise", "dom"],
"paths": {
"N": ["node_modules/@hitc/netsuite-types/N"],
"N/*": ["node_modules/@hitc/netsuite-types/N/*"]
}
},
"exclude": ["node_modules", "jest.config.ts", "**/__tests__/**"]
}
this should all you to compile your typescript files.Jay Jetley
01/30/2024, 11:20 AMconst path = require("path");
const webpack = require("webpack");
const fs = require("fs");
/**
* Folder to place packed files in
*/
const outFolder = path.resolve(
__dirname,
"deploy/FileCabinet/SuiteApps/com.netsuite.myscripts/SuiteScripts/"
);
/**
* Add All Entry point scripts here, the key will be used for output filename.
*/
const entries = {
my_suitelet: "./src/suitelets/my_suitelet/index.ts",
my_userevent: "./src/user-events/my_userevent/index.ts",
};
/**
* Add Aliases below and in tsconfig.json paths. Ensure to use absolute path or path.resolve(__dirname,<RELATIVE PATH>)
*/
const aliases = {
// helpers: path.resolve(__dirname, "src/TypeScript/helpers"),
// definitions: path.resolve(__dirname, "src/TypeScript/definitions"),
// services: path.resolve(__dirname, "src/TypeScript/services"),
};
/**
* This reads the deploy.xml and gets all the .js files that we want to deploy
* and then filters the entries-list above to only build the relevant .js-files
*/
const lineArray = fs.readFileSync("./deploy/deploy.xml").toString().split("\n");
const jsFilesToDeploy = lineArray
.filter((lineText) => lineText.includes(".js"))
.map((lineText) => /\/SuiteScripts\/(.*)[.]js/.exec(lineText)[1]);
console.log("JS-files in the deploy.xml", jsFilesToDeploy);
const entriesToDeploy = Object.entries(entries).reduce(
(filteredList, entry) => {
if (jsFilesToDeploy.includes(entry[0])) {
filteredList[entry[0]] = entry[1];
}
return filteredList;
},
{}
);
console.log("Matching entries in Webpack.config.js", entriesToDeploy);
/**
* Main Webpack Configuration, change with care
*/
module.exports = {
entry: entries,
mode: "production",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: "/node_modules/",
},
],
},
optimization: {
minimize: false,
moduleIds: "named",
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
alias: aliases,
},
plugins: [
// Copy the SuiteScript JSDoc to the top of the script
new webpack.BannerPlugin({
banner: (data) => {
const filename = data.chunk.entryModule.resource;
const contents = fs.readFileSync(filename, "UTF-8");
const comments = contents.match(/\/\*[\s\S]*?\*\//);
return comments && comments.length ? comments[0] : "";
},
raw: true,
}),
],
output: {
path: outFolder,
filename: "[name].js",
libraryTarget: "amd",
},
externals: [/^N\//],
};
Jay Jetley
01/30/2024, 11:23 AMconst entries = {
my_suitelet: "./src/suitelets/my_suitelet/index.ts",
my_userevent: "./src/user-events/my_userevent/index.ts",
};
at the top of the file. This will create a single output file for each entry point entered here and will bundle any 3rd party modules used.
Also note
const outFolder = path.resolve(
__dirname,
"deploy/FileCabinet/SuiteApps/com.netsuite.myscripts/SuiteScripts/"
);
at the top of the file which sets the output directory. We are using the the Netsuite CLI to deploy hence the reference to the FileCabinetJay Jetley
01/30/2024, 11:25 AM<deploy>
<files>
<path>~/FileCabinet/SuiteApps/com.netsuite.myscripts/SuiteScripts/*</path>
</files>
<objects>
<path>~/Objects/*</path>
</objects>
</deploy>
Jay Jetley
01/30/2024, 11:25 AMWatz
01/30/2024, 2:53 PMWatz
01/30/2024, 3:03 PMjsFilesToDeploy
, the point of referencing deploy.xml in webpack.config.js is moot.Jay Jetley
01/30/2024, 3:59 PMWatz
01/30/2024, 4:03 PM