|
| 1 | +const FaviconsWebpackPlugin = require("favicons-webpack-plugin"); |
| 2 | +const HtmlWebpackPlugin = require("html-webpack-plugin"); |
| 3 | +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); |
| 4 | +const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); |
| 5 | +const PACKAGE = require("./package"); |
| 6 | +const TerserJSPlugin = require("terser-webpack-plugin"); |
| 7 | + |
| 8 | +module.exports = (env, argv) => { |
| 9 | + const isDebug = (argv.mode === "development"); |
| 10 | + |
| 11 | + return { |
| 12 | + devServer: { |
| 13 | + host: "0.0.0.0", |
| 14 | + open: true |
| 15 | + }, |
| 16 | + entry: { |
| 17 | + index: "./src/webapp/js/index.js" |
| 18 | + }, |
| 19 | + mode: (isDebug ? "development" : "production"), |
| 20 | + module: { |
| 21 | + rules: [ |
| 22 | + { |
| 23 | + test: /\.less$/, |
| 24 | + use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"] |
| 25 | + }, |
| 26 | + { |
| 27 | + test: /worker\.js$/, |
| 28 | + loader: "worker-loader", |
| 29 | + options: { |
| 30 | + name: "[name].[ext]" |
| 31 | + } |
| 32 | + } |
| 33 | + ] |
| 34 | + }, |
| 35 | + optimization: { |
| 36 | + minimizer: (isDebug ? [] : [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin()]), |
| 37 | + }, |
| 38 | + output: { |
| 39 | + filename: "index.js", |
| 40 | + path: __dirname + "/dist/webapp", |
| 41 | + globalObject: "this" // Fix worker |
| 42 | + }, |
| 43 | + plugins: [ |
| 44 | + new HtmlWebpackPlugin({ |
| 45 | + minify: (isDebug ? false : { |
| 46 | + collapseWhitespace: true, |
| 47 | + removeComments: true, |
| 48 | + removeRedundantAttributes: true, |
| 49 | + removeScriptTypeAttributes: true, |
| 50 | + removeStyleLinkTypeAttributes: true, |
| 51 | + useShortDoctype: true |
| 52 | + }), |
| 53 | + template: "./src/webapp/html/index.html" |
| 54 | + }), |
| 55 | + new MiniCssExtractPlugin(), |
| 56 | + new FaviconsWebpackPlugin({ |
| 57 | + devMode: "webapp", |
| 58 | + logo: "./src/webapp/img/icon.svg", |
| 59 | + mode: "webapp", |
| 60 | + favicons: { |
| 61 | + appDescription: PACKAGE.description, |
| 62 | + appName: PACKAGE.productName, |
| 63 | + appShortName: PACKAGE.productName, |
| 64 | + appleStatusBarStyle: "black", |
| 65 | + background: "#FFFFFF", |
| 66 | + developerName: PACKAGE.author, |
| 67 | + developerURL: null, |
| 68 | + dir: null, |
| 69 | + display: "standalone", |
| 70 | + icons: { |
| 71 | + android: true, |
| 72 | + appleIcon: true, |
| 73 | + favicons: true, |
| 74 | + appleStartup: false, |
| 75 | + coast: false, |
| 76 | + firefox: false, |
| 77 | + windows: false, |
| 78 | + yandex: false |
| 79 | + }, |
| 80 | + lang: null, |
| 81 | + manifestRelativePaths: true, |
| 82 | + orientation: "any", |
| 83 | + path: "./", |
| 84 | + start_url: "..", |
| 85 | + theme_color: "#795548", |
| 86 | + version: PACKAGE.version |
| 87 | + }, |
| 88 | + prefix: "webapp", |
| 89 | + publicPath: "./" |
| 90 | + }) |
| 91 | + ], |
| 92 | + resolve: { |
| 93 | + alias: { |
| 94 | + fs: __dirname + "/src/fs_browser_null.js", |
| 95 | + "fs-extra": __dirname + "/src/fs_browser_null.js", |
| 96 | + "graceful-fs": __dirname + "/src/fs_browser_null.js", |
| 97 | + path: "path-browserify", // Latest version which supports `path.parse` |
| 98 | + readdirp: __dirname + "/src/fs_browser_null.js" |
| 99 | + } |
| 100 | + }, |
| 101 | + target: "web" |
| 102 | + }; |
| 103 | +}; |
0 commit comments