microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1fe78525cb3778a3fadfcad91e71c2720d5cb626

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

gulp_scripts/webpackBundle.js

122lines · modecode

1const webpack = require("webpack");
2const TerserPlugin = require("terser-webpack-plugin");
3const path = require("path");
4const srcPath = "src";
5const distDir = appRoot + "/dist";
6const distSrcDir = `${distDir}/src`;
7
8/** Run webpack to bundle the extension output files */
9async function webpackBundle() {
10 const packages = [
11 {
12 entry: `${srcPath}/extension/rn-extension.ts`,
13 filename: "rn-extension.js",
14 library: true,
15 },
16 ];
17 return runWebpack({ packages });
18}
19
20async function runWebpack({
21 packages = [],
22 devtool = false,
23 compileInPlace = false,
24 mode = process.argv.includes("watch") ? "development" : "production",
25} = options) {
26 let configs = [];
27 for (const { entry, library, filename } of packages) {
28 const config = {
29 mode,
30 target: "node",
31 entry: path.resolve(entry),
32 output: {
33 path: compileInPlace ? path.resolve(path.dirname(entry)) : path.resolve(distDir),
34 filename: filename || path.basename(entry).replace(".js", ".bundle.js"),
35 devtoolModuleFilenameTemplate: "../[resource-path]",
36 },
37 devtool: devtool,
38 resolve: {
39 extensions: [".js", ".ts", ".json"],
40 },
41 module: {
42 rules: [
43 {
44 test: /\.ts$/,
45 exclude: /node_modules/,
46 use: [
47 {
48 // vscode-nls-dev loader:
49 // * rewrite nls-calls
50 loader: "vscode-nls-dev/lib/webpack-loader",
51 options: {
52 base: path.join(appRoot),
53 },
54 },
55 {
56 // configure TypeScript loader:
57 // * enable sources maps for end-to-end source maps
58 loader: "ts-loader",
59 options: {
60 compilerOptions: {
61 sourceMap: true,
62 },
63 },
64 },
65 ],
66 },
67 ],
68 },
69 optimization: {
70 minimize: true,
71 minimizer: [
72 new TerserPlugin({
73 terserOptions: {
74 format: {
75 comments: /^\**!|@preserve/i,
76 },
77 },
78 extractComments: false,
79 }),
80 ],
81 },
82 node: {
83 __dirname: false,
84 __filename: false,
85 },
86 externals: {
87 vscode: "commonjs vscode",
88 },
89 };
90
91 if (library) {
92 config.output.libraryTarget = "commonjs2";
93 }
94
95 if (process.argv.includes("--analyze-size")) {
96 config.plugins = [
97 new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({
98 analyzerMode: "static",
99 reportFilename: path.resolve(distSrcDir, path.basename(entry) + ".html"),
100 }),
101 ];
102 }
103
104 configs.push(config);
105 }
106
107 await new Promise((resolve, reject) =>
108 webpack(configs, (err, stats) => {
109 if (err) {
110 reject(err);
111 } else if (stats.hasErrors()) {
112 reject(stats);
113 } else {
114 resolve();
115 }
116 }),
117 );
118}
119
120module.exports = {
121 webpackBundle,
122};