bitwarden-estensione-browser/webpack.config.js

171 lines
4.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-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 isVendorModule = (module) => {
if (!module.context) {
return false;
}
return module.context.indexOf('node_modules') !== -1;
};
const extractCss = new ExtractTextPlugin({
filename: '[name].css',
disable: false,
allChunks: true,
});
const moduleRules = [
{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader',
},
{
test: /\.(html)$/,
loader: 'html-loader',
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
exclude: /.*(fontawesome-webfont|glyphicons-halflings-regular)\.svg/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/',
publicPath: './images/',
},
}],
},
2018-06-05 05:10:41 +02:00
{
test: /\.scss$/,
use: extractCss.extract({
use: [
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
publicPath: '../',
}),
},
];
const plugins = [
new CleanWebpackPlugin([
path.resolve(__dirname, 'build/*'),
]),
// ref: https://github.com/angular/angular/issues/20357
new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)esm5/,
path.resolve(__dirname, './src')),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
chunks: ['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-06-05 05:26:05 +02:00
{ from: './src/manifest.json' },
{ from: './src/favicon.ico' },
{ from: './src/version.json' },
{ from: './src/browserconfig.xml' },
{ from: './src/app-id.json' },
2018-06-05 05:10:41 +02:00
{ from: './src/images', to: 'images' },
]),
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
include: ['app/main.js'],
2018-06-05 05:10:41 +02:00
}),
extractCss,
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
}),
];
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-06-05 17:14:53 +02:00
let certSuffix = fs.existsSync('dev-server.local.pem') ? '.local' : '.shared';
2018-06-05 06:02:43 +02:00
const serve = {
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-06-05 05:10:41 +02:00
const config = {
mode: ENV,
2018-06-05 06:02:43 +02:00
serve: serve,
2018-06-05 05:10:41 +02:00
entry: {
'app/main': './src/app/main.ts',
'connectors/u2f': './src/connectors/u2f.js',
'connectors/duo': './src/connectors/duo.js',
2018-06-05 05:10:41 +02:00
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
jslib: path.join(__dirname, 'jslib/src'),
},
symlinks: false,
modules: [path.resolve('node_modules')],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: isVendorModule,
name: 'app/vendor',
2018-06-05 05:10:41 +02:00
chunks: 'initial',
enforce: true,
}
}
}
},
module: { rules: moduleRules },
plugins: plugins,
};
module.exports = config;