1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-08 09:43:42 +01:00
bitwarden-browser/webpack.renderer.js

138 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-01-16 20:48:34 +01:00
const path = require('path');
const webpack = require('webpack');
2018-01-23 19:59:01 +01:00
const merge = require('webpack-merge');
2018-01-16 20:48:34 +01:00
const HtmlWebpackPlugin = require('html-webpack-plugin');
2018-01-23 19:59:01 +01:00
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
2018-01-16 20:48:34 +01:00
2018-01-23 19:59:01 +01:00
const extractCss = new ExtractTextPlugin({
filename: '[name].css',
disable: false,
2018-09-12 19:12:44 +02:00
allChunks: true,
2018-01-23 19:59:01 +01:00
});
const common = {
2018-01-16 20:48:34 +01:00
module: {
rules: [
{
test: /\.ts$/,
enforce: 'pre',
2018-09-12 19:12:44 +02:00
loader: 'tslint-loader',
2018-01-16 20:48:34 +01:00
},
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
2018-09-12 19:12:44 +02:00
loader: '@ngtools/webpack',
2018-01-16 20:48:34 +01:00
},
2018-01-30 23:24:02 +01:00
{
test: /\.(jpe?g|png|gif|svg)$/i,
exclude: /.*(fontawesome-webfont)\.svg/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/',
2018-09-12 19:12:44 +02:00
},
}],
},
],
2018-01-23 19:59:01 +01:00
},
plugins: [],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
2018-09-12 19:12:44 +02:00
jslib: path.join(__dirname, 'jslib/src'),
2018-04-04 14:30:14 +02:00
},
symlinks: false,
2018-09-12 19:12:44 +02:00
modules: [path.resolve('node_modules')],
2018-01-23 19:59:01 +01:00
},
output: {
filename: '[name].js',
2018-09-12 19:12:44 +02:00
path: path.resolve(__dirname, 'build'),
},
2018-01-23 19:59:01 +01:00
};
const renderer = {
2018-09-12 19:12:44 +02:00
mode: 'production',
2018-01-23 19:59:01 +01:00
target: 'electron-renderer',
node: {
2018-09-12 19:12:44 +02:00
__dirname: false,
2018-01-23 19:59:01 +01:00
},
entry: {
2018-09-12 19:12:44 +02:00
'app/main': './src/app/main.ts',
},
optimization: {
2018-09-14 21:55:55 +02:00
minimize: false,
2018-09-12 19:12:44 +02:00
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'app/vendor',
chunks: (chunk) => {
return chunk.name === 'app/main';
},
},
},
},
2018-01-23 19:59:01 +01:00
},
module: {
rules: [
2018-01-16 20:48:34 +01:00
{
test: /\.(html)$/,
2018-09-12 19:12:44 +02:00
loader: 'html-loader',
2018-01-16 20:48:34 +01:00
},
2018-01-22 19:27:57 +01:00
{
test: /.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
exclude: /loading.svg/,
2018-01-22 19:27:57 +01:00
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
2018-08-08 18:47:54 +02:00
},
}],
2018-01-23 19:59:01 +01:00
},
{
test: /\.scss$/,
use: extractCss.extract({
use: [
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
2018-09-12 19:12:44 +02:00
},
],
2018-09-12 19:12:44 +02:00
publicPath: '../',
}),
2018-01-23 19:59:01 +01:00
},
2018-09-12 19:12:44 +02:00
// Hide System.import warnings. ref: https://github.com/angular/angular/issues/21560
{
test: /[\/\\]@angular[\/\\].+\.js$/,
parser: { system: true },
},
],
2018-01-16 20:48:34 +01:00
},
plugins: [
new AngularCompilerPlugin({
tsConfigPath: 'tsconfig.json',
entryModule: 'src/app/app.module#AppModule',
2018-09-12 19:12:44 +02:00
sourceMap: true,
}),
2018-02-08 16:37:54 +01:00
// ref: https://github.com/angular/angular/issues/20357
2018-09-12 19:12:44 +02:00
new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)fesm5/,
2018-04-13 20:23:00 +02:00
path.resolve(__dirname, './src')),
2018-01-16 20:48:34 +01:00
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
2018-09-12 19:12:44 +02:00
chunks: ['app/vendor', 'app/main'],
2018-01-16 20:48:34 +01:00
}),
2018-01-23 19:59:01 +01:00
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
2018-09-12 19:12:44 +02:00
include: ['app/main.js'],
2018-01-23 19:59:01 +01:00
}),
2018-08-25 14:30:30 +02:00
extractCss,
2018-09-12 19:12:44 +02:00
],
2018-01-16 20:48:34 +01:00
};
2018-01-23 19:59:01 +01:00
module.exports = merge(common, renderer);