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