microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
081295f35cdc05683a9b1d9fa4cfb84633ea2cea

Branches

Tags

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

Clone

HTTPS

Download ZIP

gulp_scripts/webpackBundle.js

122lines · modeblame

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