code-server/webpack.config.app.js

166 lines
4.2 KiB
JavaScript
Raw Normal View History

2019-01-08 03:46:19 +03:00
const path = require("path");
const environment = process.env.NODE_ENV || "development";
2019-01-12 03:11:34 +03:00
const isCi = typeof process.env.CI !== "undefined";
2019-01-08 03:46:19 +03:00
const minify = isCi;
const compatibility = isCi;
2019-01-12 03:11:34 +03:00
2019-01-08 03:46:19 +03:00
const HappyPack = require("happypack");
const webpack = require("webpack");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const WriteFilePlugin = require("write-file-webpack-plugin");
const PreloadWebpackPlugin = require("preload-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
2019-01-12 03:11:34 +03:00
const root = __dirname;
const nodeFills = path.join(root, "packages", "node-browser", "src");
const vscodeFills = path.join(root, "packages", "vscode", "src", "fill");
2019-01-08 03:46:19 +03:00
module.exports = {
2019-01-12 03:11:34 +03:00
context: root,
devtool: "eval",
entry: "./packages/app/src/index.ts",
2019-01-08 03:46:19 +03:00
mode: isCi ? "production" : "development",
output: {
chunkFilename: "[name]-[hash:6].bundle.js",
2019-01-12 03:11:34 +03:00
path: path.join(root, "dist"),
2019-01-08 03:46:19 +03:00
filename: "[hash:6].bundle.js",
},
module: {
2019-01-12 03:11:34 +03:00
rules: [{
test: /\.(js)/,
exclude: /test/,
}, {
test: /\.(node|txt|d\.ts|test.ts|perf.data.js|jxs)/,
use: [{
2019-01-08 03:46:19 +03:00
loader: "ignore-loader",
2019-01-12 03:11:34 +03:00
}],
}, {
use: [{
loader: "happypack/loader?id=ts",
}],
test: /(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$/,
}, {
exclude: /test/,
test: /\.s?css$/,
// This is required otherwise it'll fail to resolve CSS in common.
include: root,
use: [{
loader: MiniCssExtractPlugin.loader,
2019-01-08 03:46:19 +03:00
}, {
2019-01-12 03:11:34 +03:00
loader: "css-loader",
2019-01-08 03:46:19 +03:00
}, {
2019-01-12 03:11:34 +03:00
loader: "sass-loader",
}],
}, {
test: /\.(svg|png|ttf|woff|eot)$/,
use: [{
loader: "file-loader",
}],
}, {
test: /\.wasm$/,
type: "javascript/auto",
}],
noParse: /\.test\.(j|t)sx?/,
2019-01-08 03:46:19 +03:00
},
resolve: {
alias: {
2019-01-12 03:11:34 +03:00
"native-keymap": path.join(vscodeFills, "native-keymap.ts"),
"node-pty": path.join(vscodeFills, "node-pty.ts"),
"gc-signals": path.join(nodeFills, "empty.ts"),
"selenium-webdriver": path.join(nodeFills, "empty.ts"),
"vscode": path.join(nodeFills, "empty.ts"),
"vscode-fsevents": path.join(nodeFills, "empty.ts"),
"vsda": path.join(nodeFills, "empty.ts"),
"windows-foreground-love": path.join(nodeFills, "empty.ts"),
"windows-mutex": path.join(nodeFills, "empty.ts"),
"windows-process-tree": path.join(nodeFills, "empty.ts"),
2019-01-08 03:46:19 +03:00
"crypto": "crypto-browserify",
"http": "http-browserify",
"os": "os-browserify",
2019-01-12 03:11:34 +03:00
"util": path.join(root, "node_modules", "util"),
"child_process": path.join(nodeFills, "child_process.ts"),
"fs": path.join(nodeFills, "fs.ts"),
"net": path.join(nodeFills, "net.ts"),
"electron": path.join(root, "packages", "electron-browser", "src", "electron.ts"),
"@coder": path.join(root, "packages"),
"vs": path.join(root, "lib", "vscode", "src", "vs"),
2019-01-08 03:46:19 +03:00
},
extensions: [".js", ".jsx", ".ts", ".tsx", ".json", ".css"],
mainFiles: [
"index",
"src/index",
],
},
resolveLoader: {
alias: {
2019-01-12 03:11:34 +03:00
"vs/css": path.join(vscodeFills, "css.js"),
2019-01-08 03:46:19 +03:00
},
modules: [
2019-01-12 03:11:34 +03:00
path.join(root, "node_modules"),
2019-01-08 03:46:19 +03:00
],
},
devServer: {
hot: true,
2019-01-12 03:11:34 +03:00
port: 3000,
2019-01-08 03:46:19 +03:00
stats: {
2019-01-12 03:11:34 +03:00
all: false, // Fallback for options not defined.
errors: true,
warnings: true,
2019-01-08 03:46:19 +03:00
},
},
plugins: [
new HtmlWebpackPlugin({
2019-01-12 03:11:34 +03:00
template: "packages/app/src/index.html",
2019-01-08 03:46:19 +03:00
}),
new HappyPack({
id: "ts",
threads: 2,
2019-01-12 03:11:34 +03:00
loaders: [{
path: "ts-loader",
query: {
happyPackMode: true,
},
}],
2019-01-08 03:46:19 +03:00
}),
// new BundleAnalyzerPlugin(),
new WriteFilePlugin({
exitOnErrors: false,
}),
new PreloadWebpackPlugin({
rel: "preload",
as: "script",
}),
new webpack.DefinePlugin({
2019-01-12 03:11:34 +03:00
"process.env.NODE_ENV": `"${environment}"`,
2019-01-08 03:46:19 +03:00
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
}),
// minify ? new UglifyJsPlugin({
// cache: true,
// parallel: true,
// sourceMap: false,
// }) : undefined,
// new ForkTsCheckerWebpackPlugin({
// checkSyntacticErrors: true,
2019-01-12 03:11:34 +03:00
// tsconfig: path.join(root, "./src/tsconfig.json"),
2019-01-08 03:46:19 +03:00
// }),
],
target: "web",
2019-01-12 03:11:34 +03:00
stats: {
all: false, // Fallback for options not defined.
errors: true,
warnings: true,
},
2019-01-08 03:46:19 +03:00
};