mirror of
https://github.com/wassname/talk.git
synced 2026-06-27 18:45:03 +08:00
c9a0ab8848
* chore: upgrade fluent * chore: upgrade metascraper * chore: upgrade akismet-api * chore: upgrade apollo-server-express * chore: upgrade archiver * chore: upgrade bull * chore: upgrade express, cheerio, content-security-policy-builder * chore: upgrade convict * chore: upgrade cors, cron * chore: upgrade csv-stringify * chore: upgrade dompurify * chore: upgrade dotenv * chore: upgrade express-static-gzip * chore: upgrade fs-extra * chore: upgrade graphql-js * chore: upgrade graphql packages * chore: upgrade html-minifier * chore: upgrade html-to-text * chore: upgrade ioredis * chore: upgrade joi * chore: upgrade jsdom * chore: upgrade jsonwebtoken * chore: upgrade juice * chore: upgrade jwks-rsa ad linkifyjs * chore: upgrade lodash * chore: upgrade luxon * chore: upgrade metascraper * chore: upgrade mongodb * chore: upgrade ms * chore: upgrade node and node-fetch types * chore: upgrade nodemailer nunjucks and typescript-eslint * chore: Upgrade passport * upgrade: prom-client react-helmet source-map-support stack-utils * chore: upgrade uuid * chore: upgrade @babel packages * chore: upgrade types * chore: upgrade autoprefixer * chore: upgrade jest * chore: upgrade ts-jest * chore: remove linkify.d.ts * chore: upgrade bowser * chore: case-sensitive-paths-webpack-plugin * chore: upgrade classnames * chore: upgrade commander * chore: upgrade comment-json * chore: upgrade cross-spawn compression-webpack-plugin del * chore: upgrade build and watch related dependencies * chore: upgrade css-vars-ponyfill * chore: upgrade eslint and css-vars-ponyfill * chore: upgrade enzyme and eventemitter2 * fix: form bug * chore: upgrade farce * chore: upgrade final form * chore: upgrade react-popper * chore: upgrade flat and fork-ts-checker-webpack-plugin * chore: upgrade husky and gulp related, intersection observer * chore: upgrade lint-staged * chore: upgrade marked, loader-utils, mini-css-extract-plugin * chore: upgrade postcss-nested, proxy-polyfill, pstree.remy * chore: upgrade prettier * chore: fix prettier changes, upgrade react * chore: mute createFactory deprecated message * chore: upgrade react-copy-to-clipbard, react-axe, react-dom, react-test-renderer, react-timeago * chore: upgrade react-transistion-group, react-responsive * chore: upgrade types * chore: upgrade react-dev-utils, react-error-overlay regenerator-runtime * chore: upgrade types, sinon, sockjs-client, strip-ansi * chore: upgrade types, fonts * chore: upgrade nunjucks, ts-node, typescript-snapshot-plugin, wait-for-expect * chore: upgrade eslint packages * chore: upgrade fluent, types * chore: upgrade jsdom dep * chore: upgrade mongo * chore: upgrade deps * chore: upgrade typescript, recompose * chore: upgrade prettier * chore: remove obsolete prettier config * chore: upgrade jsdom types * chore: upgrade typescript-eslint * chore: upgrad deps * chore: upgrade deps * chore: upgrade relay related modules * chore: upgrade docz WIP * chore: upgrade docz * chore: add guard * chore: remove obsolete line * chore: comment * chore: refactors * fix: hook count change error
217 lines
6.3 KiB
JavaScript
217 lines
6.3 KiB
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
|
|
|
|
/** Path to postCSSConfig */
|
|
const postCSSConfigPath = path.resolve(
|
|
__dirname,
|
|
"../src/core/build/postcss.config"
|
|
);
|
|
const rootDir = path.resolve(__dirname, "../");
|
|
const srcDir = path.resolve(rootDir, "./src");
|
|
const appTsconfig = path.resolve(rootDir, "./src/core/client/tsconfig.json");
|
|
|
|
const CSS_PATTERN = /\.css$/;
|
|
const MODULE_CSS_PATTERN = /\.module\.css$/;
|
|
|
|
// Define `RegExp.toJSON` so that we can stringify RegExp.
|
|
Object.defineProperty(RegExp.prototype, "toJSON", {
|
|
value: RegExp.prototype.toString,
|
|
});
|
|
|
|
const isCssRules = (rule) =>
|
|
rule.test &&
|
|
(rule.test.toString() === CSS_PATTERN.toString() ||
|
|
rule.test.toString() === MODULE_CSS_PATTERN.toString());
|
|
|
|
const findCssRules = (config) =>
|
|
config.module.rules.find(
|
|
(rule) => Array.isArray(rule.oneOf) && rule.oneOf.every(isCssRules)
|
|
);
|
|
|
|
exports.onCreateWebpackConfig = ({
|
|
stage,
|
|
rules,
|
|
loaders,
|
|
plugins,
|
|
actions,
|
|
getConfig,
|
|
}) => {
|
|
// Get webpack config.
|
|
const config = getConfig();
|
|
|
|
if (stage === "develop") {
|
|
config.entry.commons.push(
|
|
// Add our global css variables file.
|
|
`${srcDir}/core/client/ui/theme/variables.css.ts`
|
|
);
|
|
}
|
|
|
|
/*
|
|
TODO: (cvle) couldn't get build to work...
|
|
if (stage === "build-javascript") {
|
|
config.entry.app = [
|
|
config.entry.app,
|
|
`${appDir}/core/client/ui/theme/variables.css.ts`,
|
|
];
|
|
}
|
|
*/
|
|
|
|
// Find the gatsby CSS rules.
|
|
const cssRules = findCssRules(config);
|
|
// Exclude them from our src dir because they are incomaptible with our
|
|
// CSS rules.
|
|
cssRules.exclude = srcDir;
|
|
// Add .tx .tsx to modules
|
|
config.resolve.extensions.push(".ts", ".tsx");
|
|
actions.replaceWebpackConfig(config);
|
|
|
|
// Write out webpack config to .docz folder.
|
|
fs.writeFileSync(
|
|
path.resolve(__dirname, "webpack-" + stage),
|
|
JSON.stringify(config, {}, 2)
|
|
);
|
|
|
|
// Turn on sourceMap during develop.
|
|
const sourceMap = stage.startsWith("develop");
|
|
|
|
// CSS loaders to prepend.
|
|
const prependCSSLoaders = [];
|
|
if (stage === "develop") {
|
|
prependCSSLoaders.push(loaders.style());
|
|
}
|
|
|
|
/*
|
|
TODO: (cvle) couldn't get build to work...
|
|
if (stage === "build-javascript") {
|
|
moreLoaders.push(loaders.style());
|
|
}
|
|
*/
|
|
|
|
actions.setWebpackConfig({
|
|
resolve: {
|
|
plugins: [
|
|
// Resolve our custom paths.
|
|
new TsconfigPathsPlugin({
|
|
extensions: [".ts", ".tsx", ".js"],
|
|
configFile: path.resolve(rootDir, "./src/core/client/tsconfig.json"),
|
|
}),
|
|
],
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
include: srcDir,
|
|
oneOf: [
|
|
{
|
|
test: /\.css\.ts$/,
|
|
use: [
|
|
...prependCSSLoaders,
|
|
{
|
|
loader: require.resolve("css-loader"),
|
|
options: {
|
|
modules: {
|
|
localIdentName: "[name]-[local]-[hash:base64:5]",
|
|
},
|
|
importLoaders: 2,
|
|
sourceMap,
|
|
},
|
|
},
|
|
{
|
|
loader: require.resolve("postcss-loader"),
|
|
options: {
|
|
config: {
|
|
path: postCSSConfigPath,
|
|
},
|
|
parser: "postcss-js",
|
|
},
|
|
},
|
|
{
|
|
loader: require.resolve("babel-loader"),
|
|
options: {
|
|
configFile: false,
|
|
babelrc: false,
|
|
presets: [
|
|
"@babel/typescript",
|
|
[
|
|
"@babel/env",
|
|
{ targets: { node: "current" }, modules: "commonjs" },
|
|
],
|
|
],
|
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
|
// directory for faster rebuilds.
|
|
cacheDirectory: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.css$/,
|
|
use: [
|
|
...prependCSSLoaders,
|
|
{
|
|
loader: require.resolve("css-loader"),
|
|
options: {
|
|
modules: {
|
|
localIdentName: "[name]-[local]-[hash:base64:5]",
|
|
},
|
|
importLoaders: 1,
|
|
sourceMap,
|
|
},
|
|
},
|
|
{
|
|
loader: require.resolve("postcss-loader"),
|
|
options: {
|
|
config: {
|
|
path: postCSSConfigPath,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.tsx?$/,
|
|
use: [
|
|
{
|
|
loader: require.resolve("babel-loader"),
|
|
options: {
|
|
root: rootDir,
|
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
|
// directory for faster rebuilds.
|
|
cacheDirectory: true,
|
|
},
|
|
},
|
|
{
|
|
loader: require.resolve("ts-loader"),
|
|
options: {
|
|
configFile: appTsconfig,
|
|
compilerOptions: {
|
|
target: "es2015",
|
|
module: "esnext",
|
|
jsx: "preserve",
|
|
noEmit: false,
|
|
},
|
|
transpileOnly: true,
|
|
// Overwrites the behavior of `include` and `exclude` to only
|
|
// include files that are actually being imported and which
|
|
// are necessary to compile the bundle.
|
|
onlyCompileBundledFiles: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
// Write out processed webpack config to .docz folder.
|
|
fs.writeFileSync(
|
|
path.resolve(__dirname, "webpack-" + stage + "-processed"),
|
|
JSON.stringify(getConfig(), {}, 2)
|
|
);
|
|
};
|