1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-05 09:10:53 +01:00
bitwarden-browser/webpack.config.js

261 lines
8.3 KiB
JavaScript
Raw Normal View History

2018-06-05 05:10:41 +02:00
const path = require('path');
2018-06-05 06:02:43 +02:00
const fs = require('fs');
2018-06-05 05:10:41 +02:00
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
2018-06-05 05:10:41 +02:00
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInjector = require('html-webpack-injector');
2018-06-05 05:10:41 +02:00
const CopyWebpackPlugin = require('copy-webpack-plugin');
2020-05-08 17:42:28 +02:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
2018-06-05 05:10:41 +02:00
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
2018-06-11 15:31:11 +02:00
const pjson = require('./package.json');
const config = require('./config.js');
2018-06-05 05:10:41 +02:00
const ENV = process.env.ENV == null ? 'development' : process.env.ENV;
const NODE_ENV = process.env.NODE_ENV == null ? 'development' : process.env.NODE_ENV;
const envConfig = config.load(ENV);
config.log(envConfig);
2018-06-05 05:10:41 +02:00
const moduleRules = [
{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader',
},
{
test: /\.(html)$/,
loader: 'html-loader',
},
2018-07-18 16:32:44 +02:00
{
test: /.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
Dark Theme (#1017) * Stylesheets * Theme Configuration * Options Area * swal2 style * Icon styling * Fix theme not saving * Update English * Update messages.json * dropdown and login logo * btn-link and totp fix * Organisation Styling * Update webauthn-fallback.ts * Fix contrast issues * Add Paypal Container and Loading svg file * Password Generator contrast fix * Dark Mode Fix buttons and foreground * Fix button hover * Fix Styles after rebase * Add hover on nav dropdown-item * Disable Theme Preview * Options Fix for Default Theme Changes * Updated Colour Scheme * Toast fix * Button and Text Styling * Options Update and Messages Fix * Added Search Icon and Fixed Callout styling * Add theme styling to Stripe * Refactor logic for setting color * Reorder logic to avoid race condition * PayPal Loading and Misc Fix * text-state bug fix * Badge Colour Fix * Remove PayPal Tagline The colour cannot be styled so it's not visible on a dark theme * Adding the Styling from #1131 * Update to New Design * Form and Nav restyle * Modal Opacity and Callout * Nav Colours * Missing Borders * Light theme fix * Improved border for listgroup * Change Org Nav Colour * Save theme to localStorage for persistence * Undo change to Wired image * !Important removal and tweaks * Fix regression with navbar * Light theme by default * Refactor to use getEffectiveTheme * Refactor theme constants to use enum * Set theme in index.html before app loads * Use scss selector to set logo image * Export Sass to TS * Update jslib Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
2021-09-30 00:06:20 +02:00
exclude: /loading(|-white).svg/,
2018-07-18 16:32:44 +02:00
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
}],
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
2018-06-11 18:58:56 +02:00
exclude: /.*(fontawesome-webfont)\.svg/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/',
2020-05-08 17:54:49 +02:00
},
}],
},
2018-06-05 05:10:41 +02:00
{
test: /\.scss$/,
2020-05-08 17:42:28 +02:00
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../',
2020-05-08 17:54:49 +02:00
},
2020-05-08 17:42:28 +02:00
},
'css-loader',
2020-05-08 17:54:49 +02:00
'sass-loader',
2020-05-08 17:42:28 +02:00
],
2018-06-05 05:10:41 +02:00
},
2018-06-05 17:52:09 +02:00
// Hide System.import warnings. ref: https://github.com/angular/angular/issues/21560
{
test: /[\/\\]@angular[\/\\].+\.js$/,
2018-07-21 04:46:03 +02:00
parser: { system: true },
2018-06-05 17:52:09 +02:00
},
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
loader: '@ngtools/webpack',
},
2018-06-05 05:10:41 +02:00
];
const plugins = [
new CleanWebpackPlugin(),
2018-06-05 05:10:41 +02:00
// ref: https://github.com/angular/angular/issues/20357
2018-09-11 23:30:44 +02:00
new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)fesm5/,
2018-06-05 05:10:41 +02:00
path.resolve(__dirname, './src')),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
chunks: ['theme_head', 'app/polyfills', 'app/vendor', 'app/main'],
}),
new HtmlWebpackInjector(),
new HtmlWebpackPlugin({
template: './src/connectors/duo.html',
filename: 'duo-connector.html',
chunks: ['connectors/duo'],
}),
new HtmlWebpackPlugin({
template: './src/connectors/u2f.html',
filename: 'u2f-connector.html',
chunks: ['connectors/u2f'],
2018-06-05 05:10:41 +02:00
}),
2021-03-16 17:44:31 +01:00
new HtmlWebpackPlugin({
template: './src/connectors/webauthn.html',
filename: 'webauthn-connector.html',
chunks: ['connectors/webauthn'],
}),
new HtmlWebpackPlugin({
template: './src/connectors/webauthn-mobile.html',
filename: 'webauthn-mobile-connector.html',
chunks: ['connectors/webauthn'],
}),
2021-03-16 17:44:31 +01:00
new HtmlWebpackPlugin({
template: './src/connectors/webauthn-fallback.html',
filename: 'webauthn-fallback-connector.html',
chunks: ['connectors/webauthn-fallback'],
}),
new HtmlWebpackPlugin({
template: './src/connectors/sso.html',
filename: 'sso-connector.html',
chunks: ['connectors/sso'],
}),
new HtmlWebpackPlugin({
template: './src/connectors/captcha.html',
filename: 'captcha-connector.html',
chunks: ['connectors/captcha'],
}),
new HtmlWebpackPlugin({
template: './src/connectors/captcha-mobile.html',
filename: 'captcha-mobile-connector.html',
chunks: ['connectors/captcha'],
}),
new CopyWebpackPlugin({
patterns:[
{ from: './src/.nojekyll' },
{ from: './src/manifest.json' },
{ from: './src/favicon.ico' },
{ from: './src/browserconfig.xml' },
{ from: './src/app-id.json' },
{ from: './src/404.html' },
{ from: './src/404', to: '404' },
{ from: './src/images', to: 'images' },
{ from: './src/locales', to: 'locales' },
{ from: './src/scripts', to: 'scripts' },
{ from: './node_modules/qrious/dist/qrious.min.js', to: 'scripts' },
{ from: './node_modules/braintree-web-drop-in/dist/browser/dropin.js', to: 'scripts' },
{
from: './src/version.json',
transform (content, path) {
return content.toString().replace('process.env.APPLICATION_VERSION', pjson.version);
},
}
],
}),
2020-05-08 17:42:28 +02:00
new MiniCssExtractPlugin({
filename: '[name].[hash].css',
2020-05-08 17:54:49 +02:00
chunkFilename: '[id].[hash].css',
2020-05-08 17:42:28 +02:00
}),
new webpack.EnvironmentPlugin({
'ENV': ENV,
'NODE_ENV': NODE_ENV === 'production' ? 'production' : 'development',
'APPLICATION_VERSION': pjson.version,
'CACHE_TAG': Math.random().toString(36).substring(7),
'URLS': envConfig['urls'] ?? {},
'STRIPE_KEY': envConfig['stripeKey'] ?? '',
'BRAINTREE_KEY': envConfig['braintreeKey'] ?? '',
'PAYPAL_CONFIG': envConfig['paypal'] ?? {},
2018-06-05 05:10:41 +02:00
}),
new AngularCompilerPlugin({
2018-06-05 05:10:41 +02:00
tsConfigPath: 'tsconfig.json',
entryModule: 'src/app/app.module#AppModule',
sourceMap: true,
}),
];
2018-06-05 05:10:41 +02:00
2018-09-18 17:59:03 +02:00
// ref: https://webpack.js.org/configuration/dev-server/#devserver
2018-06-05 17:14:53 +02:00
let certSuffix = fs.existsSync('dev-server.local.pem') ? '.local' : '.shared';
const devServer = NODE_ENV !== 'development' ? {} : {
2018-06-05 06:02:43 +02:00
https: {
2018-06-05 17:14:53 +02:00
key: fs.readFileSync('dev-server' + certSuffix + '.pem'),
cert: fs.readFileSync('dev-server' + certSuffix + '.pem'),
2018-06-05 06:02:43 +02:00
},
2018-07-10 16:47:31 +02:00
// host: '192.168.1.9',
proxy: {
'/api': {
target: envConfig.dev?.proxyApi,
pathRewrite: {'^/api' : ''},
secure: false,
changeOrigin: true
},
'/identity': {
target: envConfig.dev?.proxyIdentity,
pathRewrite: {'^/identity' : ''},
secure: false,
changeOrigin: true
},
'/events': {
target: envConfig.dev?.proxyEvents,
pathRewrite: {'^/events' : ''},
secure: false,
changeOrigin: true
},
'/notifications': {
target: envConfig.dev?.proxyNotifications,
pathRewrite: {'^/notifications' : ''},
secure: false,
changeOrigin: true
},
},
hot: false,
allowedHosts: envConfig.dev?.allowedHosts,
};
const webpackConfig = {
mode: NODE_ENV,
2018-06-05 17:52:09 +02:00
devtool: 'source-map',
2018-09-18 17:59:03 +02:00
devServer: devServer,
2018-06-05 05:10:41 +02:00
entry: {
2018-06-08 05:38:17 +02:00
'app/polyfills': './src/app/polyfills.ts',
'app/main': './src/app/main.ts',
'connectors/u2f': './src/connectors/u2f.js',
2021-03-16 17:44:31 +01:00
'connectors/webauthn': './src/connectors/webauthn.ts',
'connectors/webauthn-fallback': './src/connectors/webauthn-fallback.ts',
2018-06-08 16:15:45 +02:00
'connectors/duo': './src/connectors/duo.ts',
'connectors/sso': './src/connectors/sso.ts',
'connectors/captcha': './src/connectors/captcha.ts',
'theme_head': './src/theme.js',
2018-06-05 05:10:41 +02:00
},
2018-06-28 04:05:33 +02:00
externals: {
'u2f': 'u2f',
},
2018-07-21 04:46:03 +02:00
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'app/vendor',
chunks: (chunk) => {
return chunk.name === 'app/main';
},
},
},
},
minimizer: [
new TerserPlugin({
terserOptions: {
safari10: true,
},
sourceMap: true,
}),
],
2018-07-21 04:46:03 +02:00
},
2018-06-05 05:10:41 +02:00
resolve: {
extensions: ['.ts', '.js'],
symlinks: false,
modules: [path.resolve('node_modules')],
},
output: {
2018-09-11 23:30:44 +02:00
filename: '[name].[hash].js',
2018-06-05 05:10:41 +02:00
path: path.resolve(__dirname, 'build'),
},
module: { rules: moduleRules },
plugins: plugins,
};
module.exports = webpackConfig;