Herbert Eiselt | 3d202a0 | 2019-02-11 14:54:12 +0100 | [diff] [blame] | 1 | /**
|
| 2 | * Webpack 4 configuration file
|
| 3 | * see https://webpack.js.org/configuration/
|
| 4 | * see https://webpack.js.org/configuration/dev-server/
|
| 5 | */
|
| 6 |
|
| 7 | "use strict";
|
| 8 |
|
| 9 | const path = require("path");
|
| 10 | const webpack = require("webpack");
|
| 11 | const CopyWebpackPlugin = require("copy-webpack-plugin");
|
| 12 | const requirejsPlugin = require('requirejs-webpack-plugin');
|
| 13 | const TerserPlugin = require('terser-webpack-plugin');
|
| 14 |
|
| 15 | // const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
|
| 16 |
|
| 17 | module.exports = (env) => {
|
| 18 | const distPath = path.resolve(__dirname, env === "release" ? "." : "..", "dist");
|
| 19 | const frameworkPath = path.resolve(__dirname, env === "release" ? "." : "..", "dist");
|
| 20 | return [{
|
| 21 | name: "Client",
|
| 22 | mode: "none", //disable default behavior
|
| 23 | target: "web",
|
| 24 |
|
| 25 | context: path.resolve(__dirname, "src"),
|
| 26 |
|
| 27 | entry: {
|
| 28 | app: [
|
| 29 | "./app.tsx",
|
| 30 | "./services",
|
| 31 | "./components/material-table",
|
| 32 | "./components/material-ui",
|
| 33 | "./utilities/elasticSearch",
|
| 34 | "./models"],
|
| 35 | },
|
| 36 |
|
| 37 | devtool: env === "release" ? false : "source-map",
|
| 38 |
|
| 39 | resolve: {
|
| 40 | extensions: [".ts", ".tsx", ".js", ".jsx"]
|
| 41 | },
|
| 42 |
|
| 43 | output: {
|
| 44 | path: distPath,
|
| 45 | library: "[name]", // related to webpack.DllPlugin::name
|
| 46 | libraryTarget: "umd2",
|
| 47 | filename: "[name].js",
|
| 48 | chunkFilename: "[name].js"
|
| 49 | },
|
| 50 |
|
| 51 | module: {
|
| 52 | rules: [{
|
| 53 | test: /\.tsx?$/,
|
| 54 | exclude: /node_modules/,
|
| 55 | use: [{
|
| 56 | loader: "babel-loader"
|
| 57 | }, {
|
| 58 | loader: "ts-loader"
|
| 59 | }]
|
| 60 | }, {
|
| 61 | test: /\.jsx?$/,
|
| 62 | exclude: /node_modules/,
|
| 63 | use: [{
|
| 64 | loader: "babel-loader"
|
| 65 | }]
|
| 66 | }, {
|
| 67 | test: /\.(png|gif|jpg|svg)$/,
|
| 68 | use: [{
|
| 69 | loader: 'url-loader',
|
| 70 | options: {
|
| 71 | limit: 10000,
|
| 72 | name: './images/[hash].[ext]'
|
| 73 | }
|
| 74 | }]
|
| 75 | }]
|
| 76 | },
|
| 77 |
|
| 78 | optimization: {
|
| 79 | noEmitOnErrors: true,
|
| 80 | namedModules: env !== "release",
|
| 81 | minimize: env === "release",
|
| 82 | minimizer: env !== "release" ? [] : [new TerserPlugin({
|
| 83 | terserOptions: {
|
| 84 | mangle:{
|
Herbert Eiselt | 2d4424c | 2019-03-12 18:00:21 +0100 | [diff] [blame^] | 85 | reserved:["./app.tsx"]
|
Herbert Eiselt | 3d202a0 | 2019-02-11 14:54:12 +0100 | [diff] [blame] | 86 | },
|
| 87 | warnings: false, // false, true, "verbose"
|
| 88 | compress: {
|
| 89 | drop_console: true,
|
| 90 | drop_debugger: true,
|
| 91 | }
|
| 92 | }
|
| 93 | })],
|
| 94 | },
|
| 95 |
|
| 96 | plugins: [
|
| 97 | new CopyWebpackPlugin([{
|
| 98 | from: '../../node_modules/requirejs/require.js',
|
| 99 | to: '.'
|
| 100 | }, {
|
| 101 | from: './favicon.ico',
|
| 102 | to: '.'
|
| 103 | }, {
|
| 104 | from: env === "release" ? './index.html' : 'index.dev.html',
|
| 105 | to: './index.html'
|
| 106 | }]),
|
| 107 | new requirejsPlugin({
|
| 108 | path: distPath,
|
| 109 | filename: 'config.js',
|
| 110 | baseUrl: '',
|
| 111 | pathUrl: '',
|
| 112 | processOutput: function (assets) {
|
| 113 | return 'require.config(' + JSON.stringify(assets, null, 2) + ')';
|
| 114 | }
|
| 115 | }),
|
| 116 | // new HtmlWebpackPlugin({
|
| 117 | // filename: "index.html",
|
| 118 | // template: "./index.html",
|
| 119 | // inject: "head"
|
| 120 | // }),
|
| 121 | // new HtmlWebpackIncludeAssetsPlugin({
|
| 122 | // assets: ['vendor.js'],
|
| 123 | // append: false
|
| 124 | // }),
|
| 125 | new webpack.DllReferencePlugin({
|
| 126 | context: path.resolve(__dirname, "src"),
|
| 127 | manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
|
| 128 | sourceType: "umd2"
|
| 129 | }),
|
| 130 | new webpack.DllPlugin({
|
| 131 | context: path.resolve(__dirname, "src"),
|
| 132 | name: "[name]",
|
| 133 | path: path.resolve(distPath, "[name]-manifest.json")
|
| 134 | }),
|
| 135 | ...(env === "release") ? [
|
| 136 | new webpack.DefinePlugin({
|
| 137 | "process.env": {
|
| 138 | NODE_ENV: "'production'",
|
| 139 | VERSION: JSON.stringify(require("./package.json").version)
|
| 140 | }
|
| 141 | }),
|
| 142 | ] : [
|
| 143 | new webpack.HotModuleReplacementPlugin(),
|
| 144 | new webpack.DefinePlugin({
|
| 145 | "process.env": {
|
| 146 | NODE_ENV: "'development'",
|
| 147 | VERSION: JSON.stringify(require("./package.json").version)
|
| 148 | }
|
| 149 | }),
|
| 150 | new webpack.WatchIgnorePlugin([
|
| 151 | /css\.d\.ts$/,
|
| 152 | /less\.d\.ts$/
|
| 153 | ])
|
| 154 | ]
|
| 155 | ],
|
| 156 |
|
| 157 | devServer: {
|
| 158 | public: "http://localhost:3100",
|
| 159 | contentBase: distPath,
|
| 160 |
|
| 161 | compress: true,
|
| 162 | headers: {
|
| 163 | "Access-Control-Allow-Origin": "*"
|
| 164 | },
|
| 165 | host: "0.0.0.0",
|
| 166 | port: 3100,
|
| 167 | disableHostCheck: true,
|
| 168 | historyApiFallback: true,
|
| 169 | inline: true,
|
| 170 | hot: false,
|
| 171 | quiet: false,
|
| 172 | stats: {
|
| 173 | colors: true
|
| 174 | },
|
| 175 | proxy: {
|
Herbert Eiselt | 2d4424c | 2019-03-12 18:00:21 +0100 | [diff] [blame^] | 176 | "/oauth2/**/*": {
|
| 177 | target: "http://localhost:3000",
|
Herbert Eiselt | 3d202a0 | 2019-02-11 14:54:12 +0100 | [diff] [blame] | 178 | secure: false
|
| 179 | }
|
| 180 | }
|
| 181 | }
|
| 182 |
|
| 183 | }];
|
| 184 | }
|
| 185 |
|
| 186 |
|