photoprism/frontend/webpack.config.js

209 lines
6.3 KiB
JavaScript
Raw Normal View History

const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require("webpack");
2018-09-13 20:54:34 +02:00
const isDev = process.env.NODE_ENV !== "production";
if(isDev) {
console.log("Building frontend in DEVELOPMENT mode. Please wait.");
} else {
console.log("Building frontend in PRODUCTION mode. Please wait.");
}
const PATHS = {
app: path.join(__dirname, "src/app.js"),
js: path.join(__dirname, "src"),
css: path.join(__dirname, "src/css"),
build: path.join(__dirname, "../assets/resources/static/build"),
};
const config = {
mode: isDev ? "development" : "production",
devtool: isDev ? "inline-source-map" : false,
entry: {
app: PATHS.app,
},
output: {
path: PATHS.build,
filename: "[name].js",
},
resolve: {
modules: [
path.join(__dirname, "src"),
path.join(__dirname, "node_modules"),
],
alias: {
vue: isDev ? "vue/dist/vue.js" : "vue/dist/vue.min.js",
},
},
plugins: [
2019-05-07 15:41:33 +02:00
new MiniCssExtractPlugin({
filename: "[name].css",
2019-05-07 15:41:33 +02:00
}),
],
node: {
fs: "empty",
},
2019-05-07 15:41:33 +02:00
performance: {
hints: isDev ? false : "error",
maxEntrypointSize: 3000000,
maxAssetSize: 3000000,
2019-05-07 15:41:33 +02:00
},
module: {
rules: [
{
test: /\.js$/,
include: PATHS.app,
exclude: /node_modules/,
enforce: "pre",
loader: "eslint-loader",
options: {
formatter: require("eslint-formatter-pretty"),
},
},
{
test: /\.vue$/,
loader: "vue-loader",
include: PATHS.js,
options: {
loaders: {
js: "babel-loader",
css: "css-loader",
},
2019-05-07 15:41:33 +02:00
},
},
{
test: /\.js$/,
loader: "babel-loader",
include: PATHS.js,
2019-05-07 15:41:33 +02:00
exclude: file => (
/node_modules/.test(file)
),
query: {
presets: ["@babel/preset-env"],
compact: false,
},
},
{
test: /\.css$/,
include: PATHS.css,
exclude: /node_modules/,
2019-05-07 15:41:33 +02:00
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: false,
fallback: "vue-style-loader",
2019-05-07 15:41:33 +02:00
use: [
"style-loader",
2019-05-07 15:41:33 +02:00
{
loader: "css-loader",
2019-05-07 15:41:33 +02:00
options: {
importLoaders: 1,
sourceMap: isDev,
2019-05-07 15:41:33 +02:00
},
},
{
loader: "postcss-loader",
2019-05-07 15:41:33 +02:00
options: {
sourceMap: isDev,
config: {
path: path.resolve(__dirname, "./postcss.config.js"),
2019-05-07 15:41:33 +02:00
},
},
},
"resolve-url-loader",
2019-05-07 15:41:33 +02:00
],
publicPath: PATHS.build,
},
},
"css-loader",
],
},
{
test: /\.css$/,
include: /node_modules/,
2019-05-07 15:41:33 +02:00
loaders: [
"vue-style-loader",
"style-loader",
2019-05-07 15:41:33 +02:00
{
loader: "css-loader",
2019-05-07 15:41:33 +02:00
options: { importLoaders: 1, sourceMap: isDev },
},
{
loader: "postcss-loader",
2019-05-07 15:41:33 +02:00
options: {
sourceMap: isDev,
config: {
path: path.resolve(__dirname, "./postcss.config.js"),
2019-05-07 15:41:33 +02:00
},
},
},
"resolve-url-loader",
],
},
{
2019-05-07 15:41:33 +02:00
test: /\.s[c|a]ss$/,
use: [
"vue-style-loader",
"style-loader",
2019-05-07 15:41:33 +02:00
{
loader: "css-loader",
2019-05-07 15:41:33 +02:00
options: { importLoaders: 2, sourceMap: isDev },
},
{
loader: "postcss-loader",
2019-05-07 15:41:33 +02:00
options: {
sourceMap: isDev,
config: {
path: path.resolve(__dirname, "./postcss.config.js"),
2019-05-07 15:41:33 +02:00
},
},
},
"resolve-url-loader",
"sass-loader",
],
2019-05-07 15:41:33 +02:00
},
{
2019-05-07 15:41:33 +02:00
test: /\.(png|jpg|jpeg|gif)$/,
loader: "file-loader",
options: {
name: "[hash].[ext]",
publicPath: "/static/build/img",
outputPath: "img",
},
},
{
2019-05-07 15:41:33 +02:00
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
loader: "file-loader",
2019-05-07 15:41:33 +02:00
options: {
name: "[hash].[ext]",
publicPath: "/static/build/fonts",
outputPath: "fonts",
},
},
{
test: /\.svg/,
use: {
loader: "svg-url-loader",
options: {},
},
},
],
},
};
// No sourcemap for production
2019-05-07 15:41:33 +02:00
if (isDev) {
2018-09-13 20:54:34 +02:00
const devToolPlugin = new webpack.SourceMapDevToolPlugin({
filename: "[file].map",
2018-09-13 20:54:34 +02:00
});
config.plugins.push(devToolPlugin);
}
2019-05-07 15:41:33 +02:00
module.exports = config;