bitwarden-desktop/webpack.renderer.js

143 lines
4.0 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-22 19:27:57 +01:00
const GoogleFontsPlugin = require("google-fonts-webpack-plugin");
2018-01-23 19:59:01 +01:00
const ExtractTextPlugin = require('extract-text-webpack-plugin');
2018-01-16 20:48:34 +01:00
const isVendorModule = (module) => {
if (!module.context) {
return false;
}
const nodeModule = module.context.indexOf('node_modules') !== -1;
const bitwardenModule = module.context.indexOf('@bitwarden') !== -1;
return nodeModule && !bitwardenModule;
};
2018-01-23 19:59:01 +01:00
const extractCss = new ExtractTextPlugin({
filename: '[name].css',
disable: false,
allChunks: true
});
const common = {
2018-01-16 20:48:34 +01:00
module: {
rules: [
{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader'
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules\/(?!(@bitwarden)\/).*/
},
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-01-23 19:59:01 +01:00
]
},
plugins: [],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
2018-02-19 22:06:26 +01:00
jslib: path.join(__dirname, 'jslib/src')
2018-01-23 19:59:01 +01:00
}
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build')
}
};
const renderer = {
target: 'electron-renderer',
node: {
__dirname: false
},
entry: {
'app/main': './src/app/main.ts'
},
module: {
rules: [
2018-01-16 20:48:34 +01:00
{
test: /\.(html)$/,
loader: 'html-loader'
},
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/',
publicPath: '../'
2018-01-22 19:27:57 +01:00
}
}]
2018-01-23 19:59:01 +01:00
},
{
test: /\.scss$/,
use: extractCss.extract({
use: [
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
}
],
publicPath: '../'
2018-01-23 19:59:01 +01:00
})
},
2018-01-16 20:48:34 +01:00
]
},
plugins: [
2018-01-22 19:27:57 +01:00
new GoogleFontsPlugin({
fonts: [
{
family: 'Open Sans',
variants: ['300', '300italic', '400', '400italic', '600', '600italic',
'700', '700italic', '800', '800italic'],
subsets: ['cyrillic', 'cyrillic-ext', 'greek', 'greek-ext', 'latin', 'latin-ext']
}
],
formats: ['woff2'],
path: 'fonts/',
filename: 'css/fonts.css'
}),
2018-02-08 16:37:54 +01:00
// ref: https://github.com/angular/angular/issues/20357
new webpack.ContextReplacementPlugin(
/\@angular(\\|\/)core(\\|\/)esm5/,
path.resolve(__dirname, './src')
),
2018-01-16 20:48:34 +01:00
new webpack.optimize.CommonsChunkPlugin({
2018-01-16 23:30:57 +01:00
name: 'app/vendor',
chunks: ['app/main'],
2018-01-16 20:48:34 +01:00
minChunks: isVendorModule
}),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
2018-01-16 23:30:57 +01: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',
include: ['app/main.js']
}),
extractCss
]
2018-01-16 20:48:34 +01:00
};
2018-01-23 19:59:01 +01:00
module.exports = merge(common, renderer);