2021-07-09 18:36:45 +08:00
|
|
|
const path = require("path");
|
|
|
|
const glob = require("glob");
|
2021-08-14 16:44:46 +08:00
|
|
|
const webpack = require("webpack");
|
2021-07-09 18:36:45 +08:00
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
|
|
|
const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");
|
2021-01-08 03:55:45 +08:00
|
|
|
|
2021-03-17 18:17:52 +08:00
|
|
|
// Make sure NODE_ENV is set, so that @tailwindcss/jit is in watch mode in development.
|
2021-07-09 18:36:45 +08:00
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || "development";
|
2021-03-17 18:17:52 +08:00
|
|
|
|
2021-01-08 03:55:45 +08:00
|
|
|
module.exports = (env, options) => {
|
2021-07-09 18:36:45 +08:00
|
|
|
const devMode = options.mode !== "production";
|
2021-01-08 03:55:45 +08:00
|
|
|
|
|
|
|
return {
|
2021-07-09 18:36:45 +08:00
|
|
|
mode: options.mode || "production",
|
2021-01-08 03:55:45 +08:00
|
|
|
entry: {
|
2021-07-09 18:36:45 +08:00
|
|
|
app: glob.sync("./vendor/**/*.js").concat(["./js/app.js"]),
|
2021-01-08 03:55:45 +08:00
|
|
|
},
|
|
|
|
output: {
|
2021-07-09 18:36:45 +08:00
|
|
|
filename: "[name].js",
|
|
|
|
path: path.resolve(
|
|
|
|
__dirname,
|
2021-10-19 04:32:09 +08:00
|
|
|
devMode ? "../tmp/static_dev/js" : "../static/js"
|
2021-07-09 18:36:45 +08:00
|
|
|
),
|
|
|
|
publicPath: "/js/",
|
2021-01-08 03:55:45 +08:00
|
|
|
},
|
2021-07-09 18:36:45 +08:00
|
|
|
devtool: devMode ? "eval-cheap-module-source-map" : undefined,
|
2021-01-08 03:55:45 +08:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2021-07-09 18:36:45 +08:00
|
|
|
loader: "babel-loader",
|
|
|
|
},
|
2021-01-08 03:55:45 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.[s]?css$/,
|
2021-07-09 18:36:45 +08:00
|
|
|
use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"],
|
2021-01-21 20:11:45 +08:00
|
|
|
},
|
|
|
|
{
|
2021-03-12 18:57:01 +08:00
|
|
|
test: /\.(ttf|woff|woff2|eot|svg)$/,
|
2021-10-19 06:37:48 +08:00
|
|
|
type: "asset/resource",
|
2021-01-21 20:11:45 +08:00
|
|
|
},
|
2021-07-09 18:36:45 +08:00
|
|
|
],
|
2021-01-08 03:55:45 +08:00
|
|
|
},
|
|
|
|
plugins: [
|
2021-08-14 16:44:46 +08:00
|
|
|
// Polyfill the global "process" variable required by "remark" internals
|
|
|
|
new webpack.ProvidePlugin({
|
2021-10-19 06:37:48 +08:00
|
|
|
process: "process/browser.js",
|
2021-08-14 16:44:46 +08:00
|
|
|
}),
|
2021-07-09 18:36:45 +08:00
|
|
|
new MiniCssExtractPlugin({ filename: "../css/app.css" }),
|
2021-01-21 20:11:45 +08:00
|
|
|
new MonacoWebpackPlugin({
|
2021-07-09 18:36:45 +08:00
|
|
|
languages: ["markdown", "elixir"],
|
|
|
|
}),
|
2021-05-13 05:44:45 +08:00
|
|
|
],
|
|
|
|
optimization: {
|
2021-07-09 18:36:45 +08:00
|
|
|
minimizer: ["...", new CssMinimizerPlugin()],
|
2021-05-13 05:44:45 +08:00
|
|
|
},
|
2021-07-09 18:36:45 +08:00
|
|
|
resolve: {
|
|
|
|
fallback: {
|
2021-08-14 16:44:46 +08:00
|
|
|
// The crypto-js package relies no the crypto module, but it has
|
|
|
|
// fine support in browsers, so we don't provide polyfills
|
2021-07-09 18:36:45 +08:00
|
|
|
crypto: false,
|
2021-08-14 16:44:46 +08:00
|
|
|
// Polyfill the assert module required by "remark" internals
|
|
|
|
assert: require.resolve("assert"),
|
2021-07-09 18:36:45 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2021-01-08 03:55:45 +08:00
|
|
|
};
|