bones73k/assets/webpack.config.js

106 lines
3 KiB
JavaScript
Raw Normal View History

2021-02-24 12:02:48 -05:00
const path = require("path");
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 16:03:03 -05:00
const SpriteLoaderPlugin = require("svg-sprite-loader/plugin");
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$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader",
"postcss-loader",
],
2021-02-24 12:02:48 -05:00
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
esModule: false,
name: "[name].[ext]",
outputPath: "../fonts",
},
},
],
},
2021-02-25 16:03:03 -05:00
{
test: /\.svg$/,
loader: "svg-sprite-loader",
options: {
extract: true,
spriteFilename: "icons.svg",
publicPath: "../images/",
symbolId: (filePath) => {
if (filePath.includes("bootstrap-icons")) {
2021-02-25 16:05:35 -05:00
return `bi-${path.basename(filePath).slice(0, -4)}`;
2021-02-25 16:03:03 -05:00
} else if (filePath.includes("@mdi")) {
return `mdi-${path.basename(filePath).slice(0, -4)}`;
} else if (filePath.includes("heroicons")) {
if (filePath.includes("outline")) {
return `hio-${path.basename(filePath).slice(0, -4)}`;
} else {
return `his-${path.basename(filePath).slice(0, -4)}`;
}
2021-02-25 16:03:03 -05:00
} else {
return `${path.basename(filePath).slice(0, -4)}`;
}
},
},
},
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" }),
2021-02-25 16:03:03 -05:00
new SpriteLoaderPlugin({ plainSprite: true }),
2021-02-24 12:02:48 -05:00
new CopyWebpackPlugin({
patterns: [{ from: "static/", to: "../" }],
}),
].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
};