Signal-Desktop/webpack.config.ts

100 lines
2.5 KiB
TypeScript
Raw Permalink Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { resolve } from 'path';
// eslint-disable-next-line import/no-extraneous-dependencies
2021-04-07 19:59:58 +00:00
import { Configuration, EnvironmentPlugin, ProvidePlugin } from 'webpack';
2019-12-17 20:25:57 +00:00
import HtmlWebpackPlugin = require('html-webpack-plugin');
2021-12-07 18:46:08 +00:00
import TerserPlugin = require('terser-webpack-plugin');
2019-12-17 20:25:57 +00:00
const context = __dirname;
const { NODE_ENV: mode = 'development' } = process.env;
const isDev = mode === 'development';
const csp = `
default-src 'none';
child-src 'self';
connect-src 'self'${isDev ? ' http: ws:' : ''};
font-src 'self';
form-action 'self';
frame-src 'none';
img-src 'self' blob: data:;
media-src 'self' blob:;
object-src 'none';
script-src 'self'${isDev ? " 'unsafe-eval'" : ''};
style-src 'self' 'unsafe-inline';
`;
const stickerCreatorConfig: Configuration = {
context,
mode: mode as Configuration['mode'],
entry: [
'react-hot-loader/patch',
'sanitize.css',
'typeface-inter',
'./sticker-creator/index.tsx',
],
2021-12-07 18:46:08 +00:00
// Stack-traces have to be readable so don't mangle function names.
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: false,
keep_classnames: true,
keep_fnames: true,
},
}),
],
},
2019-12-17 20:25:57 +00:00
output: {
path: resolve(context, 'sticker-creator/dist'),
filename: 'bundle.js',
publicPath: mode === 'production' ? './' : '/sticker-creator/dist/',
},
module: {
rules: [
{
test: /\.tsx?$/,
2021-04-07 19:59:58 +00:00
use: [{ loader: 'babel-loader' }],
2019-12-17 20:25:57 +00:00
},
{
test: /\.css$/,
2021-04-07 19:59:58 +00:00
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
2019-12-17 20:25:57 +00:00
},
{
test: /\.scss$/,
2021-04-07 19:59:58 +00:00
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader?modules=true&localsConvention=camelCaseOnly' },
{ loader: 'sass-loader' },
2019-12-17 20:25:57 +00:00
],
},
{
test: /\.woff2?$/,
2021-04-07 19:59:58 +00:00
use: [{ loader: 'file-loader' }],
2019-12-17 20:25:57 +00:00
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js'],
alias: {},
},
plugins: [
2021-04-07 19:59:58 +00:00
new ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
2019-12-17 20:25:57 +00:00
new EnvironmentPlugin(['NODE_ENV']),
new HtmlWebpackPlugin({
title: 'Signal Sticker Creator',
template: resolve(context, 'sticker-creator/index.html'),
meta: {
'Content-Security-Policy': {
'http-equiv': 'Content-Security-Policy',
content: csp,
},
},
}),
],
};
2021-04-14 19:43:11 +00:00
export default [stickerCreatorConfig];