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;
|
|
|
|
|
2021-08-10 11:46:09 +02:00
|
|
|
const webpack = require('webpack');
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
const path = require('path');
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (NPM_TARGET === 'build:watch' || NPM_TARGET === 'debug:watch') {
|
|
|
|
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', () => {
|
|
|
|
exec('cd .. && make deploy-from-watch', (err, stdout, stderr) => {
|
|
|
|
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',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/i,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
'css-loader',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(tsx?|js|jsx|mjs|html)$/,
|
|
|
|
use: [
|
|
|
|
],
|
|
|
|
exclude: [/node_modules/],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|eot|tiff|svg|woff2|woff|ttf|jpg)$/,
|
|
|
|
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-08-04 16:57:56 +02:00
|
|
|
outputPath: path.join(__dirname, '/dist'),
|
2021-08-11 00:16:57 +02:00
|
|
|
publicPath: '/plugins/focalboard/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,
|
|
|
|
};
|