code-server-2/webpack.config.app.js

167 lines
4.1 KiB
JavaScript
Raw Normal View History

2019-01-08 00:46:19 +00:00
const path = require("path");
const environment = process.env.NODE_ENV || "development";
2019-01-12 00:11:34 +00:00
const isCi = typeof process.env.CI !== "undefined";
2019-01-08 00:46:19 +00:00
const minify = isCi;
const compatibility = isCi;
2019-01-12 00:11:34 +00:00
2019-01-08 00:46:19 +00: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 00:11:34 +00:00
const root = __dirname;
const fills = path.join(root, "packages", "ide", "src", "fill");
2019-01-12 00:11:34 +00:00
const vscodeFills = path.join(root, "packages", "vscode", "src", "fill");
2019-01-08 00:46:19 +00:00
module.exports = {
2019-01-12 00:11:34 +00:00
context: root,
2019-01-14 23:19:29 +00:00
devtool: "eval",
2019-01-14 21:06:06 +00:00
entry: "./packages/web/src/index.ts",
2019-01-08 00:46:19 +00:00
mode: isCi ? "production" : "development",
output: {
chunkFilename: "[name]-[hash:6].bundle.js",
2019-01-12 00:11:34 +00:00
path: path.join(root, "dist"),
2019-01-08 00:46:19 +00:00
filename: "[hash:6].bundle.js",
},
module: {
2019-01-12 00:11:34 +00:00
rules: [{
test: /\.(js)/,
exclude: /test/,
}, {
test: /\.(node|txt|d\.ts|test.ts|perf.data.js|jxs)/,
use: [{
2019-01-08 00:46:19 +00:00
loader: "ignore-loader",
2019-01-12 00:11:34 +00: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 00:46:19 +00:00
}, {
2019-01-12 00:11:34 +00:00
loader: "css-loader",
2019-01-08 00:46:19 +00:00
}, {
2019-01-12 00:11:34 +00: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 00:46:19 +00:00
},
resolve: {
alias: {
2019-01-12 00:11:34 +00:00
"native-keymap": path.join(vscodeFills, "native-keymap.ts"),
"node-pty": path.join(vscodeFills, "node-pty.ts"),
"gc-signals": path.join(fills, "empty.ts"),
"selenium-webdriver": path.join(fills, "empty.ts"),
"vscode": path.join(fills, "empty.ts"),
"vscode-fsevents": path.join(fills, "empty.ts"),
"vsda": path.join(fills, "empty.ts"),
"windows-foreground-love": path.join(fills, "empty.ts"),
"windows-mutex": path.join(fills, "empty.ts"),
"windows-process-tree": path.join(fills, "empty.ts"),
2019-01-08 00:46:19 +00:00
"crypto": "crypto-browserify",
"http": "http-browserify",
"os": "os-browserify",
2019-01-12 00:11:34 +00:00
"child_process": path.join(fills, "child_process.ts"),
"fs": path.join(fills, "fs.ts"),
"net": path.join(fills, "net.ts"),
"util": path.join(fills, "util.ts"),
2019-01-12 00:11:34 +00:00
"electron": path.join(fills, "electron.ts"),
2019-01-12 00:11:34 +00:00
"@coder": path.join(root, "packages"),
"vs": path.join(root, "lib", "vscode", "src", "vs"),
2019-01-08 00:46:19 +00:00
},
extensions: [".js", ".jsx", ".ts", ".tsx", ".json", ".css"],
mainFiles: [
"index",
"src/index",
],
},
resolveLoader: {
alias: {
2019-01-12 00:11:34 +00:00
"vs/css": path.join(vscodeFills, "css.js"),
2019-01-08 00:46:19 +00:00
},
modules: [
2019-01-12 00:11:34 +00:00
path.join(root, "node_modules"),
2019-01-08 00:46:19 +00:00
],
},
devServer: {
hot: true,
2019-01-12 00:11:34 +00:00
port: 3000,
2019-01-14 23:19:29 +00:00
disableHostCheck: true,
2019-01-08 00:46:19 +00:00
stats: {
2019-01-12 00:11:34 +00:00
all: false, // Fallback for options not defined.
errors: true,
warnings: true,
2019-01-08 00:46:19 +00:00
},
},
plugins: [
new HtmlWebpackPlugin({
2019-01-14 21:06:06 +00:00
template: "packages/web/src/index.html",
2019-01-08 00:46:19 +00:00
}),
new HappyPack({
id: "ts",
threads: 2,
2019-01-12 00:11:34 +00:00
loaders: [{
path: "ts-loader",
query: {
happyPackMode: true,
},
}],
2019-01-08 00:46:19 +00:00
}),
// new BundleAnalyzerPlugin(),
new WriteFilePlugin({
exitOnErrors: false,
}),
new PreloadWebpackPlugin({
rel: "preload",
as: "script",
}),
new webpack.DefinePlugin({
2019-01-12 00:11:34 +00:00
"process.env.NODE_ENV": `"${environment}"`,
2019-01-08 00:46:19 +00: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 00:11:34 +00:00
// tsconfig: path.join(root, "./src/tsconfig.json"),
2019-01-08 00:46:19 +00:00
// }),
],
target: "web",
2019-01-12 00:11:34 +00:00
stats: {
all: false, // Fallback for options not defined.
errors: true,
warnings: true,
},
2019-01-08 00:46:19 +00:00
};