Merge pull request #2117 from thelounge/webpack4

Upgrade to webpack 4; tracking pr
This commit is contained in:
Pavel Djundik 2018-04-06 12:59:07 +03:00 committed by GitHub
commit 6626fbcfbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1495 additions and 539 deletions

9
client/css/fontawesome.css vendored Normal file
View File

@ -0,0 +1,9 @@
@font-face {
/* We use free solid icons - https://fontawesome.com/icons?s=solid&m=free */
font-family: "FontAwesome";
font-weight: normal;
font-style: normal;
src:
url("../fonts/fa-solid-900.woff2") format("woff2"),
url("../fonts/fa-solid-900.woff") format("woff");
}

View File

@ -1,12 +1,6 @@
@font-face { @import "fontawesome.css";
/* We use free solid icons - https://fontawesome.com/icons?s=solid&m=free */ @import "bootstrap.css";
font-family: "FontAwesome"; @import "../../node_modules/primer-tooltips/build/build.css";
font-weight: normal;
font-style: normal;
src:
url("../fonts/fa-solid-900.woff2") format("woff2"),
url("../fonts/fa-solid-900.woff") format("woff");
}
html, html,
body { body {

View File

@ -7,8 +7,6 @@
<link rel="preload" as="script" href="js/bundle.vendor.js"> <link rel="preload" as="script" href="js/bundle.vendor.js">
<link rel="preload" as="script" href="js/bundle.js"> <link rel="preload" as="script" href="js/bundle.js">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/primer-tooltips.css">
<link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="css/style.css">
<link id="theme" rel="stylesheet" href="themes/<%- theme %>.css" data-server-theme="<%- theme %>"> <link id="theme" rel="stylesheet" href="themes/<%- theme %>.css" data-server-theme="<%- theme %>">
<% _.forEach(stylesheets, function(css) { %> <% _.forEach(stylesheets, function(css) { %>

View File

@ -67,24 +67,26 @@
"devDependencies": { "devDependencies": {
"@fortawesome/fontawesome-free-webfonts": "1.0.5", "@fortawesome/fontawesome-free-webfonts": "1.0.5",
"babel-core": "6.26.0", "babel-core": "6.26.0",
"babel-loader": "7.1.2", "babel-loader": "7.1.4",
"babel-preset-env": "1.6.1", "babel-preset-env": "1.6.1",
"chai": "4.1.2", "chai": "4.1.2",
"copy-webpack-plugin": "4.5.1", "copy-webpack-plugin": "4.5.1",
"css-loader": "0.28.11",
"css.escape": "1.5.1", "css.escape": "1.5.1",
"emoji-regex": "6.5.1", "emoji-regex": "6.5.1",
"eslint": "4.19.1", "eslint": "4.19.1",
"fuzzy": "0.1.3", "fuzzy": "0.1.3",
"graphql-request": "1.5.1", "graphql-request": "1.5.1",
"handlebars": "4.0.11", "handlebars": "4.0.11",
"handlebars-loader": "1.6.0", "handlebars-loader": "1.7.0",
"intersection-observer": "0.5.0", "intersection-observer": "0.5.0",
"istanbul-instrumenter-loader": "3.0.1", "istanbul-instrumenter-loader": "3.0.1",
"jquery": "3.3.1", "jquery": "3.3.1",
"jquery-ui": "1.12.1", "jquery-ui": "1.12.1",
"mini-css-extract-plugin": "0.4.0",
"mocha": "5.0.5", "mocha": "5.0.5",
"mocha-loader": "1.1.3", "mocha-loader": "1.1.3",
"mocha-webpack": "1.0.1", "mocha-webpack": "2.0.0-beta.0",
"mousetrap": "1.6.1", "mousetrap": "1.6.1",
"npm-run-all": "4.1.2", "npm-run-all": "4.1.2",
"nyc": "11.6.0", "nyc": "11.6.0",
@ -94,7 +96,8 @@
"stylelint-config-standard": "18.2.0", "stylelint-config-standard": "18.2.0",
"textcomplete": "0.17.1", "textcomplete": "0.17.1",
"undate": "0.2.4", "undate": "0.2.4",
"webpack": "3.11.0", "webpack": "4.5.0",
"webpack-dev-server": "2.11.1" "webpack-cli": "2.0.14",
"webpack-dev-server": "3.1.1"
} }
} }

View File

@ -29,7 +29,7 @@ if (!fs.existsSync(path.join(
"public", "public",
"manifest.json" "manifest.json"
))) { ))) {
log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production npm run build")} to resolve this.`); log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production yarn build")} to resolve this.`);
process.exit(1); process.exit(1);
} }

View File

@ -10,7 +10,7 @@ config.entry = {
// Instrumentation for testing with mocha // Instrumentation for testing with mocha
config.module.rules.push({ config.module.rules.push({
test: /\.js$/, test: /\.js$/,
include: path.join(__dirname, "test/client"), include: path.join(__dirname, "test/client/js/*"),
use: "mocha-loader", use: "mocha-loader",
}); });

View File

@ -1,7 +1,6 @@
"use strict"; "use strict";
const path = require("path"); const path = require("path");
const webpack = require("webpack");
const config = require("./webpack.config.js"); const config = require("./webpack.config.js");
config.target = "node"; config.target = "node";
@ -17,10 +16,9 @@ config.module.rules.push({
enforce: "post", enforce: "post",
}); });
// `CommonsChunkPlugin` is incompatible with a `target` of `node`. // `optimization.splitChunks` is incompatible with a `target` of `node`. See:
// See https://github.com/zinserjan/mocha-webpack/issues/84 // - https://github.com/zinserjan/mocha-webpack/issues/84
config.plugins = config.plugins.filter((a) => // - https://github.com/webpack/webpack/issues/6727#issuecomment-372589122
!(a instanceof webpack.optimize.CommonsChunkPlugin) config.optimization.splitChunks = false;
);
module.exports = config; module.exports = config;

View File

@ -3,14 +3,13 @@
const webpack = require("webpack"); const webpack = require("webpack");
const path = require("path"); const path = require("path");
const CopyPlugin = require("copy-webpack-plugin"); const CopyPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// ********************
// Common configuration
// ********************
const config = { const config = {
mode: process.env.NODE_ENV === "production" ? "production" : "development",
entry: { entry: {
"js/bundle.js": path.resolve(__dirname, "client/js/lounge.js"), "js/bundle.js": path.resolve(__dirname, "client/js/lounge.js"),
"css/style": path.resolve(__dirname, "client/css/style.css"),
}, },
devtool: "source-map", devtool: "source-map",
output: { output: {
@ -20,6 +19,22 @@ const config = {
}, },
module: { module: {
rules: [ rules: [
{
test: /\.css$/,
include: [
path.resolve(__dirname, "client"),
],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
url: false,
minimize: process.env.NODE_ENV === "production",
},
},
],
},
{ {
test: /\.js$/, test: /\.js$/,
include: [ include: [
@ -57,10 +72,22 @@ const config = {
}, },
], ],
}, },
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "js/bundle.vendor.js",
chunks: "all",
},
},
},
},
externals: { externals: {
json3: "JSON", // socket.io uses json3.js, but we do not target any browsers that need it json3: "JSON", // socket.io uses json3.js, but we do not target any browsers that need it
}, },
plugins: [ plugins: [
new MiniCssExtractPlugin(),
new CopyPlugin([ new CopyPlugin([
{ {
from: "./node_modules/@fortawesome/fontawesome-free-webfonts/webfonts/fa-solid-900.woff*", from: "./node_modules/@fortawesome/fontawesome-free-webfonts/webfonts/fa-solid-900.woff*",
@ -87,34 +114,10 @@ const config = {
from: "./client/themes/*", from: "./client/themes/*",
to: "themes/[name].[ext]", to: "themes/[name].[ext]",
}, },
{ // TODO: Build css with postcss
from: "./client/css/*",
to: "css/[name].[ext]",
},
{
from: "./node_modules/primer-tooltips/build/build.css",
to: "css/primer-tooltips.[ext]",
},
]), ]),
// socket.io uses debug, we don't need it // socket.io uses debug, we don't need it
new webpack.NormalModuleReplacementPlugin(/debug/, path.resolve(__dirname, "scripts/noop.js")), new webpack.NormalModuleReplacementPlugin(/debug/, path.resolve(__dirname, "scripts/noop.js")),
// automatically split all vendor dependencies into a separate bundle
new webpack.optimize.CommonsChunkPlugin({
name: "js/bundle.vendor.js",
minChunks: (module) => module.context && module.context.includes("node_modules"),
}),
], ],
}; };
// *********************************
// Production-specific configuration
// *********************************
if (process.env.NODE_ENV === "production") {
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
comments: false,
}));
}
module.exports = config; module.exports = config;

1925
yarn.lock

File diff suppressed because it is too large Load Diff