2021-07-29 20:08:39 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
2021-05-24 19:06:11 +02:00
|
|
|
const exec = require('child_process').exec;
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
|
2021-10-22 18:13:31 +02:00
|
|
|
const webpack = require('webpack');
|
|
|
|
|
2021-07-29 20:08:39 +02:00
|
|
|
const tsTransformer = require('@formatjs/ts-transformer');
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
const PLUGIN_ID = require('../plugin.json').id;
|
|
|
|
|
|
|
|
const NPM_TARGET = process.env.npm_lifecycle_event; //eslint-disable-line no-process-env
|
|
|
|
let mode = 'production';
|
2021-07-29 20:08:39 +02:00
|
|
|
let devtool;
|
2021-08-10 11:46:09 +02:00
|
|
|
const plugins = [];
|
2021-05-24 19:06:11 +02:00
|
|
|
if (NPM_TARGET === 'debug' || NPM_TARGET === 'debug:watch') {
|
|
|
|
mode = 'development';
|
|
|
|
devtool = 'source-map';
|
2021-08-10 11:46:09 +02:00
|
|
|
plugins.push(
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.NODE_ENV': JSON.stringify('development'),
|
|
|
|
}),
|
|
|
|
);
|
2021-05-24 19:06:11 +02:00
|
|
|
}
|
|
|
|
|
2021-10-04 10:06:54 +02:00
|
|
|
if (NPM_TARGET === 'build:watch' || NPM_TARGET === 'debug:watch' || NPM_TARGET === 'live-watch') {
|
2021-05-24 19:06:11 +02:00
|
|
|
plugins.push({
|
|
|
|
apply: (compiler) => {
|
|
|
|
compiler.hooks.watchRun.tap('WatchStartPlugin', () => {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log('Change detected. Rebuilding webapp.');
|
|
|
|
});
|
|
|
|
compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => {
|
2021-10-04 10:06:54 +02:00
|
|
|
let command = 'cd .. && make deploy-from-watch';
|
|
|
|
if (NPM_TARGET === 'live-watch') {
|
|
|
|
command = 'cd .. && make deploy-to-mattermost-directory';
|
|
|
|
}
|
|
|
|
exec(command, (err, stdout, stderr) => {
|
2021-05-24 19:06:11 +02:00
|
|
|
if (stdout) {
|
|
|
|
process.stdout.write(stdout);
|
|
|
|
}
|
|
|
|
if (stderr) {
|
|
|
|
process.stderr.write(stderr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
entry: [
|
|
|
|
'./src/index.tsx',
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
modules: [
|
|
|
|
'src',
|
|
|
|
'node_modules',
|
|
|
|
path.resolve(__dirname),
|
|
|
|
],
|
2021-08-11 19:55:41 +02:00
|
|
|
alias: {
|
|
|
|
moment: path.resolve(__dirname, '../../webapp/node_modules/moment/'),
|
|
|
|
},
|
2021-05-24 19:06:11 +02:00
|
|
|
extensions: ['*', '.js', '.jsx', '.ts', '.tsx'],
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2021-07-29 20:08:39 +02:00
|
|
|
test: /\.tsx?$/,
|
2021-05-24 19:06:11 +02:00
|
|
|
use: {
|
2021-07-29 20:08:39 +02:00
|
|
|
loader: 'ts-loader',
|
2021-05-24 19:06:11 +02:00
|
|
|
options: {
|
2021-07-29 20:08:39 +02:00
|
|
|
getCustomTransformers: {
|
|
|
|
before: [
|
|
|
|
tsTransformer.transform({
|
|
|
|
overrideIdFn: '[sha512:contenthash:base64:6]',
|
|
|
|
ast: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2021-05-24 19:06:11 +02:00
|
|
|
},
|
|
|
|
},
|
2021-07-29 20:08:39 +02:00
|
|
|
exclude: [/node_modules/],
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.html$/,
|
|
|
|
type: 'asset/resource',
|
2021-05-24 19:06:11 +02:00
|
|
|
},
|
|
|
|
{
|
2021-07-29 20:08:39 +02:00
|
|
|
test: /\.s[ac]ss$/i,
|
2021-05-24 19:06:11 +02:00
|
|
|
use: [
|
|
|
|
'style-loader',
|
2021-07-29 20:08:39 +02:00
|
|
|
'css-loader',
|
|
|
|
'sass-loader',
|
2021-08-25 13:05:12 +02:00
|
|
|
path.resolve(__dirname, 'loaders/globalScssClassLoader'),
|
2021-07-29 20:08:39 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/i,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
'css-loader',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(tsx?|js|jsx|mjs|html)$/,
|
|
|
|
use: [
|
|
|
|
],
|
|
|
|
exclude: [/node_modules/],
|
|
|
|
},
|
|
|
|
{
|
2022-02-28 12:28:16 +01:00
|
|
|
test: /\.(png|eot|tiff|svg|woff2|woff|ttf|jpg|gif)$/,
|
2021-07-29 20:08:39 +02:00
|
|
|
use: [
|
2021-05-24 19:06:11 +02:00
|
|
|
{
|
2021-07-29 20:08:39 +02:00
|
|
|
loader: 'file-loader',
|
2021-05-24 19:06:11 +02:00
|
|
|
options: {
|
2021-07-29 20:08:39 +02:00
|
|
|
name: '[name].[ext]',
|
2021-10-04 22:58:56 +02:00
|
|
|
outputPath: 'static',
|
2022-01-17 20:21:25 +01:00
|
|
|
publicPath: '/static/',
|
2021-05-24 19:06:11 +02:00
|
|
|
},
|
|
|
|
},
|
2021-07-29 20:08:39 +02:00
|
|
|
{
|
|
|
|
loader: 'image-webpack-loader',
|
|
|
|
options: {},
|
|
|
|
},
|
2021-05-24 19:06:11 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
externals: {
|
|
|
|
react: 'React',
|
|
|
|
redux: 'Redux',
|
|
|
|
'react-redux': 'ReactRedux',
|
2021-08-11 11:10:52 +02:00
|
|
|
'mm-react-router-dom': 'ReactRouterDom',
|
2021-05-24 19:06:11 +02:00
|
|
|
'prop-types': 'PropTypes',
|
|
|
|
'react-bootstrap': 'ReactBootstrap',
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
devtoolNamespace: PLUGIN_ID,
|
|
|
|
path: path.join(__dirname, '/dist'),
|
|
|
|
publicPath: '/',
|
|
|
|
filename: 'main.js',
|
|
|
|
},
|
|
|
|
devtool,
|
|
|
|
mode,
|
|
|
|
plugins,
|
|
|
|
};
|
2021-09-01 23:53:27 +02:00
|
|
|
|
|
|
|
const env = {};
|
|
|
|
env.RUDDER_KEY = JSON.stringify(process.env.RUDDER_KEY || ''); //eslint-disable-line no-process-env
|
|
|
|
env.RUDDER_DATAPLANE_URL = JSON.stringify(process.env.RUDDER_DATAPLANE_URL || ''); //eslint-disable-line no-process-env
|
|
|
|
|
|
|
|
module.exports.plugins.push(new webpack.DefinePlugin({
|
|
|
|
'process.env': env,
|
|
|
|
}));
|