2021-02-24 12:02:48 -05:00
|
|
|
const path = require("path");
|
2021-02-25 15:27:31 -05:00
|
|
|
const glob = require("glob-all");
|
2021-02-24 12:02:48 -05:00
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
|
|
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
2021-02-25 15:27:31 -05:00
|
|
|
const PurgecssPlugin = require("purgecss-webpack-plugin");
|
2020-09-12 18:43:17 -04:00
|
|
|
|
|
|
|
module.exports = (env, options) => {
|
2021-02-24 12:02:48 -05:00
|
|
|
const devMode = options.mode !== "production";
|
2020-09-12 18:43:17 -04:00
|
|
|
|
|
|
|
return {
|
|
|
|
entry: {
|
2021-02-24 12:02:48 -05:00
|
|
|
app: glob.sync("./vendor/**/*.js").concat(["./js/app.js"]),
|
2020-09-12 18:43:17 -04:00
|
|
|
},
|
|
|
|
output: {
|
2021-02-24 12:02:48 -05:00
|
|
|
path: path.resolve(__dirname, "../priv/static/js"),
|
|
|
|
filename: "[name].js",
|
|
|
|
publicPath: "/js/",
|
2020-09-12 18:43:17 -04:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2021-02-24 12:02:48 -05:00
|
|
|
loader: "babel-loader",
|
|
|
|
},
|
2020-09-12 18:43:17 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.[s]?css$/,
|
2021-02-25 15:27:31 -05:00
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
"css-loader",
|
|
|
|
"sass-loader",
|
|
|
|
"postcss-loader",
|
|
|
|
],
|
2021-02-24 12:02:48 -05:00
|
|
|
},
|
|
|
|
],
|
2020-09-12 18:43:17 -04:00
|
|
|
},
|
|
|
|
plugins: [
|
2021-02-24 12:02:48 -05:00
|
|
|
new MiniCssExtractPlugin({ filename: "../css/app.css" }),
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [{ from: "static/", to: "../" }],
|
|
|
|
}),
|
2021-02-25 15:27:31 -05:00
|
|
|
].concat(
|
|
|
|
devMode
|
|
|
|
? []
|
|
|
|
: [
|
|
|
|
new PurgecssPlugin({
|
|
|
|
paths: glob.sync([
|
|
|
|
"../**/*.html.leex",
|
|
|
|
"../**/*.html.eex",
|
|
|
|
"../**/views/**/*.ex",
|
|
|
|
"../**/live/**/*.ex",
|
|
|
|
"./js/**/*.js",
|
|
|
|
]),
|
|
|
|
safelist: [/phx/, /topbar/],
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
),
|
2021-02-24 12:02:48 -05:00
|
|
|
optimization: {
|
|
|
|
minimizer: ["...", new CssMinimizerPlugin()],
|
|
|
|
},
|
|
|
|
devtool: devMode ? "source-map" : undefined,
|
|
|
|
};
|
2020-09-12 18:43:17 -04:00
|
|
|
};
|