127 lines
3.4 KiB
JavaScript
127 lines
3.4 KiB
JavaScript
// Production config
|
|
const path = require("path");
|
|
const merge = require("webpack-merge");
|
|
|
|
const resolve = path.resolve;
|
|
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
|
|
const nodeExternals = require('webpack-node-externals');
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
const WebpackCdnPlugin = require('webpack-cdn-plugin');
|
|
|
|
/* NOTE: This is a list of all routes that are prerendered for production use.
|
|
Please list all routes that contain search engine accessible content, i.e.,
|
|
stuff that you would like to find with a Google Search. */
|
|
|
|
const commonConfig = require("./common");
|
|
|
|
module.exports = function (env, argv) {
|
|
const base = commonConfig(env, argv);
|
|
base.mode = "production";
|
|
base.entry = "./index.tsx";
|
|
base.output = {
|
|
path: resolve(__dirname, "../../dist"),
|
|
publicPath: "/",
|
|
};
|
|
base.devtool = "source-map";
|
|
base.plugins.push(
|
|
new MiniCssExtractPlugin({
|
|
// Options similar to the same options in webpackOptions.output
|
|
// both options are optional
|
|
filename: "assets/styles.css?[hash]",
|
|
}),
|
|
);
|
|
|
|
if (env.platform === 'server') {
|
|
base.entry = "./server/index.ts";
|
|
base.output.filename = 'js/server.js?[hash]';
|
|
base.target = 'node';
|
|
base.externals = [nodeExternals()];
|
|
|
|
base.module.rules.push({
|
|
test: /\.css$/,
|
|
use: [
|
|
MiniCssExtractPlugin.loader,
|
|
{loader: "css-loader", options: {importLoaders: 1}},
|
|
"postcss-loader"
|
|
],
|
|
});
|
|
|
|
base.module.rules.push({
|
|
test: /\.scss$/,
|
|
loaders: [
|
|
MiniCssExtractPlugin.loader,
|
|
{loader: "css-loader", options: {importLoaders: 1}},
|
|
"postcss-loader",
|
|
{
|
|
loader: 'sass-loader',
|
|
options: {
|
|
// Prefer `dart-sass`
|
|
implementation: require('sass'),
|
|
},
|
|
},
|
|
]
|
|
});
|
|
}
|
|
|
|
else if (env.platform === 'client') {
|
|
base.entry = './client/index.ts';
|
|
base.output.filename = 'js/client.js?[hash]';
|
|
base.target = 'web';
|
|
|
|
base.module.rules.push({
|
|
test: /\.css$/,
|
|
use: [
|
|
MiniCssExtractPlugin.loader,
|
|
{loader: "css-loader", options: {importLoaders: 1}},
|
|
"postcss-loader"
|
|
],
|
|
});
|
|
|
|
base.module.rules.push({
|
|
test: /\.scss$/,
|
|
loaders: [
|
|
MiniCssExtractPlugin.loader,
|
|
{loader: "css-loader", options: {importLoaders: 1}},
|
|
"postcss-loader",
|
|
{
|
|
loader: 'sass-loader',
|
|
options: {
|
|
// Prefer `dart-sass`
|
|
implementation: require('sass'),
|
|
},
|
|
},
|
|
]
|
|
});
|
|
|
|
base.plugins.push(
|
|
new HtmlWebpackPlugin({
|
|
template: "index.html.ejs",
|
|
}),
|
|
new FaviconsWebpackPlugin({
|
|
logo: "./assets/img/favicon.png",
|
|
prefix: "assets/icons/",
|
|
icons: {
|
|
android: true,
|
|
appleIcon: true,
|
|
appleStartup: true,
|
|
coast: true,
|
|
favicons: true,
|
|
firefox: true,
|
|
opengraph: true,
|
|
twitter: true,
|
|
yandex: true,
|
|
windows: true
|
|
}
|
|
}),
|
|
new WebpackCdnPlugin({
|
|
modules: [
|
|
{ name: 'react', var: 'React', path: `umd/react.${process.env.NODE_ENV}.min.js` },
|
|
{ name: 'react-dom', var: 'ReactDOM', path: `umd/react-dom.${process.env.NODE_ENV}.min.js` },
|
|
],
|
|
}),
|
|
);
|
|
}
|
|
|
|
return base;
|
|
}; |