|
@@ -1,56 +1,58 @@
|
|
|
/* eslint-env node */
|
|
/* eslint-env node */
|
|
|
|
|
|
|
|
-import { Configuration as WebpackConfiguration } from "webpack";
|
|
|
|
|
-import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";
|
|
|
|
|
-import * as path from "path";
|
|
|
|
|
-import { ConsoleRemotePlugin } from "@openshift-console/dynamic-plugin-sdk-webpack";
|
|
|
|
|
|
|
+import * as path from 'path';
|
|
|
|
|
+import { Configuration as WebpackConfiguration } from 'webpack';
|
|
|
|
|
+import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
|
|
|
|
|
+import { ConsoleRemotePlugin } from '@openshift-console/dynamic-plugin-sdk-webpack';
|
|
|
|
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
|
|
|
|
|
|
+const isProd = process.env.NODE_ENV === 'production';
|
|
|
|
|
+
|
|
|
interface Configuration extends WebpackConfiguration {
|
|
interface Configuration extends WebpackConfiguration {
|
|
|
devServer?: WebpackDevServerConfiguration;
|
|
devServer?: WebpackDevServerConfiguration;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const config: Configuration = {
|
|
const config: Configuration = {
|
|
|
- mode: "development",
|
|
|
|
|
- // No regular entry points. The remote container entry is handled by ConsoleRemotePlugin.
|
|
|
|
|
|
|
+ mode: isProd ? 'production' : 'development',
|
|
|
|
|
+ // No regular entry points needed. All plugin related scripts are generated via ConsoleRemotePlugin.
|
|
|
entry: {},
|
|
entry: {},
|
|
|
- context: path.resolve(__dirname, "src"),
|
|
|
|
|
|
|
+ context: path.resolve(__dirname, 'src'),
|
|
|
output: {
|
|
output: {
|
|
|
- path: path.resolve(__dirname, "dist"),
|
|
|
|
|
- filename: "[name]-bundle.js",
|
|
|
|
|
- chunkFilename: "[name]-chunk.js",
|
|
|
|
|
|
|
+ path: path.resolve(__dirname, 'dist'),
|
|
|
|
|
+ filename: isProd ? '[name]-bundle-[hash].min.js' : '[name]-bundle.js',
|
|
|
|
|
+ chunkFilename: isProd ? '[name]-chunk-[chunkhash].min.js' : '[name]-chunk.js',
|
|
|
},
|
|
},
|
|
|
resolve: {
|
|
resolve: {
|
|
|
- extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
|
|
|
|
|
+ extensions: ['.ts', '.tsx', '.js', '.jsx'],
|
|
|
},
|
|
},
|
|
|
module: {
|
|
module: {
|
|
|
rules: [
|
|
rules: [
|
|
|
{
|
|
{
|
|
|
test: /\.(jsx?|tsx?)$/,
|
|
test: /\.(jsx?|tsx?)$/,
|
|
|
- exclude: /node_modules/,
|
|
|
|
|
|
|
+ exclude: /\/node_modules\//,
|
|
|
use: [
|
|
use: [
|
|
|
{
|
|
{
|
|
|
- loader: "ts-loader",
|
|
|
|
|
|
|
+ loader: 'ts-loader',
|
|
|
options: {
|
|
options: {
|
|
|
- configFile: path.resolve(__dirname, "tsconfig.json"),
|
|
|
|
|
|
|
+ configFile: path.resolve(__dirname, 'tsconfig.json'),
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- test: /\.css$/,
|
|
|
|
|
- use: ["style-loader", "css-loader"],
|
|
|
|
|
|
|
+ test: /\.(css)$/,
|
|
|
|
|
+ use: ['style-loader', 'css-loader'],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
test: /\.(png|jpg|jpeg|gif|svg|woff2?|ttf|eot|otf)(\?.*$|$)/,
|
|
test: /\.(png|jpg|jpeg|gif|svg|woff2?|ttf|eot|otf)(\?.*$|$)/,
|
|
|
type: 'asset/resource',
|
|
type: 'asset/resource',
|
|
|
generator: {
|
|
generator: {
|
|
|
- filename: 'assets/[name].[ext]',
|
|
|
|
|
|
|
+ filename: isProd ? 'assets/[contenthash][ext]' : 'assets/[name][ext]',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- test: /\.m?js/,
|
|
|
|
|
|
|
+ test: /\.(m?js)$/,
|
|
|
resolve: {
|
|
resolve: {
|
|
|
fullySpecified: false,
|
|
fullySpecified: false,
|
|
|
},
|
|
},
|
|
@@ -60,41 +62,28 @@ const config: Configuration = {
|
|
|
devServer: {
|
|
devServer: {
|
|
|
static: './dist',
|
|
static: './dist',
|
|
|
port: 9001,
|
|
port: 9001,
|
|
|
- // Allow bridge running in a container to connect to the plugin dev server.
|
|
|
|
|
|
|
+ // Allow Bridge running in a container to connect to the plugin dev server.
|
|
|
allowedHosts: 'all',
|
|
allowedHosts: 'all',
|
|
|
headers: {
|
|
headers: {
|
|
|
- "Access-Control-Allow-Origin": "*",
|
|
|
|
|
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
|
|
|
- "Access-Control-Allow-Headers": "X-Requested-With, Content-Type, Authorization"
|
|
|
|
|
|
|
+ 'Access-Control-Allow-Origin': '*',
|
|
|
|
|
+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
|
|
|
+ 'Access-Control-Allow-Headers': 'X-Requested-With, Content-Type, Authorization',
|
|
|
},
|
|
},
|
|
|
devMiddleware: {
|
|
devMiddleware: {
|
|
|
writeToDisk: true,
|
|
writeToDisk: true,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
plugins: [
|
|
plugins: [
|
|
|
- new ConsoleRemotePlugin(),
|
|
|
|
|
|
|
+ new ConsoleRemotePlugin(),
|
|
|
new CopyWebpackPlugin({
|
|
new CopyWebpackPlugin({
|
|
|
patterns: [{ from: path.resolve(__dirname, 'locales'), to: 'locales' }],
|
|
patterns: [{ from: path.resolve(__dirname, 'locales'), to: 'locales' }],
|
|
|
}),
|
|
}),
|
|
|
],
|
|
],
|
|
|
- devtool: "source-map",
|
|
|
|
|
|
|
+ devtool: isProd ? false : 'source-map',
|
|
|
optimization: {
|
|
optimization: {
|
|
|
- chunkIds: "named",
|
|
|
|
|
- minimize: false,
|
|
|
|
|
|
|
+ chunkIds: isProd ? 'deterministic' : 'named',
|
|
|
|
|
+ minimize: isProd,
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-if (process.env.NODE_ENV === "production") {
|
|
|
|
|
- config.mode = "production";
|
|
|
|
|
- if (config.output) {
|
|
|
|
|
- config.output.filename = '[name]-bundle-[hash].min.js';
|
|
|
|
|
- config.output.chunkFilename = '[name]-chunk-[chunkhash].min.js';
|
|
|
|
|
- }
|
|
|
|
|
- if (config.optimization) {
|
|
|
|
|
- config.optimization.chunkIds = 'deterministic';
|
|
|
|
|
- config.optimization.minimize = true;
|
|
|
|
|
- }
|
|
|
|
|
- config.devtool = false;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
export default config;
|
|
export default config;
|