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

189 lines
5.5 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');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
2018-06-11 15:31:11 +02:00
const pjson = require('./package.json');
2018-06-05 05:10:41 +02:00
2018-06-05 06:31:06 +02:00
if (process.env.NODE_ENV == null) {
2018-06-05 05:10:41 +02:00
process.env.NODE_ENV = 'development';
}
const ENV = process.env.ENV = process.env.NODE_ENV;
const extractCss = new ExtractTextPlugin({
2018-09-11 23:30:44 +02:00
filename: '[name].[hash].css',
2018-06-05 05:10:41 +02:00
disable: false,
allChunks: true,
});
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]+)?$/,
exclude: /loading.svg/,
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/',
2018-06-11 18:58:56 +02:00
}
}]
},
2018-06-05 05:10:41 +02:00
{
test: /\.scss$/,
use: extractCss.extract({
use: [
2018-07-21 04:46:03 +02:00
{ loader: 'css-loader' },
{ loader: 'sass-loader' },
2018-06-05 05:10:41 +02:00
],
publicPath: '../',
}),
},
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
},
2018-06-05 05:10:41 +02:00
];
const plugins = [
new CleanWebpackPlugin([
path.resolve(__dirname, 'build/*'),
]),
// 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',
2018-07-21 04:46:03 +02:00
chunks: ['app/polyfills', 'app/vendor', 'app/main'],
}),
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
}),
new CopyWebpackPlugin([
2018-09-22 22:04:09 +02:00
{ from: './src/.nojekyll' },
2018-06-05 05:26:05 +02:00
{ from: './src/manifest.json' },
{ from: './src/favicon.ico' },
{ from: './src/browserconfig.xml' },
{ from: './src/app-id.json' },
2018-06-05 05:10:41 +02:00
{ from: './src/images', to: 'images' },
2018-06-05 21:02:53 +02:00
{ from: './src/locales', to: 'locales' },
2018-06-27 23:50:31 +02:00
{ from: './src/scripts', to: 'scripts' },
2018-07-14 05:15:09 +02:00
{ from: './node_modules/qrious/dist/qrious.min.js', to: 'scripts' },
{ from: './node_modules/braintree-web-drop-in/dist/browser/dropin.js', to: 'scripts' },
2018-06-05 05:10:41 +02:00
]),
extractCss,
new webpack.DefinePlugin({
'process.env': {
2018-06-11 15:31:11 +02:00
'ENV': JSON.stringify(ENV),
2018-06-30 20:14:52 +02:00
'SELF_HOST': JSON.stringify(process.env.SELF_HOST === 'true' ? true : false),
2018-06-11 15:31:11 +02:00
'APPLICATION_VERSION': JSON.stringify(pjson.version),
2018-06-11 15:37:29 +02:00
'CACHE_TAG': JSON.stringify(Math.random().toString(36).substring(7)),
2018-06-05 05:10:41 +02:00
}
}),
];
if (ENV === 'production') {
moduleRules.push({
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
loader: '@ngtools/webpack',
});
plugins.push(new AngularCompilerPlugin({
tsConfigPath: 'tsconfig.json',
entryModule: 'src/app/app.module#AppModule',
sourceMap: true,
}));
} else {
moduleRules.push({
test: /\.ts$/,
loaders: ['ts-loader', 'angular2-template-loader'],
exclude: path.resolve(__dirname, 'node_modules'),
});
}
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';
2018-09-18 17:59:03 +02:00
const devServer = {
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',
2018-09-18 17:59:03 +02:00
hot: false,
2018-06-05 06:02:43 +02:00
};
2018-06-05 05:10:41 +02:00
const config = {
mode: 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',
2018-06-08 16:15:45 +02:00
'connectors/duo': './src/connectors/duo.ts',
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';
},
},
},
},
},
2018-06-05 05:10:41 +02:00
resolve: {
extensions: ['.ts', '.js'],
alias: {
jslib: path.join(__dirname, 'jslib/src'),
2018-10-14 05:26:38 +02:00
tldjs: path.join(__dirname, 'jslib/src/misc/tldjs.noop'),
2018-06-05 05:10:41 +02:00
},
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 = config;