open-pod/assets/webpack.config.js

52 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2020-09-02 23:19:20 +02:00
const path = require("path");
const glob = require("glob");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
2020-05-22 22:04:15 +02:00
module.exports = (env, options) => {
2020-09-02 23:19:20 +02:00
const devMode = options.mode !== "production";
2020-05-22 22:04:15 +02:00
return {
optimization: {
minimizer: [
new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }),
2020-09-02 23:19:20 +02:00
new OptimizeCSSAssetsPlugin({}),
],
2020-05-22 22:04:15 +02:00
},
entry: {
2020-09-02 23:19:20 +02:00
app: glob.sync("./vendor/**/*.js").concat(["./js/app.js"]),
2020-05-22 22:04:15 +02:00
},
output: {
2020-09-02 23:19:20 +02:00
filename: "[name].js",
path: path.resolve(__dirname, "../priv/static/js"),
publicPath: "/js/",
2020-05-22 22:04:15 +02:00
},
2020-09-02 23:19:20 +02:00
devtool: devMode ? "source-map" : undefined,
2020-05-22 22:04:15 +02:00
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
2020-09-02 23:19:20 +02:00
loader: "babel-loader",
},
},
{
test: /\.(woff|woff2|ttf|eot)$/,
use: "file-loader?name=fonts/[name].[ext]!static",
2020-05-22 22:04:15 +02:00
},
{
test: /\.[s]?css$/,
2020-09-02 23:19:20 +02:00
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
},
],
2020-05-22 22:04:15 +02:00
},
plugins: [
2020-09-02 23:19:20 +02:00
new MiniCssExtractPlugin({ filename: "../css/app.css" }),
new CopyWebpackPlugin([{ from: "static/", to: "../" }]),
],
};
2020-05-22 22:04:15 +02:00
};