2019-01-06 13:09:45 +01:00
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
const StringReplacePlugin = require('string-replace-webpack-plugin');
|
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
|
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
2019-08-16 18:45:11 +02:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2019-01-06 13:09:45 +01:00
|
|
|
|
|
|
|
const pkg = require('./package.json');
|
|
|
|
|
2019-08-16 18:45:11 +02:00
|
|
|
process.noDeprecation = true; // for css loaders
|
|
|
|
|
|
|
|
function config(grunt, mode = 'production') {
|
|
|
|
const devMode = mode === 'development';
|
2019-01-06 15:51:45 +01:00
|
|
|
const date = grunt.config.get('date');
|
2019-01-06 13:09:45 +01:00
|
|
|
const dt = date.toISOString().replace(/T.*/, '');
|
|
|
|
const year = date.getFullYear();
|
|
|
|
return {
|
2019-08-16 18:45:11 +02:00
|
|
|
mode,
|
2019-01-06 13:09:45 +01:00
|
|
|
entry: {
|
2019-09-13 23:25:57 +02:00
|
|
|
app: ['babel-helpers', 'app', 'main.scss'],
|
2019-08-16 23:05:39 +02:00
|
|
|
vendor: [
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'kdbxweb',
|
|
|
|
'baron',
|
|
|
|
'pikaday',
|
|
|
|
'jsqrcode',
|
|
|
|
'argon2-wasm',
|
2019-09-14 22:12:02 +02:00
|
|
|
'argon2',
|
|
|
|
'marked'
|
2019-08-16 23:05:39 +02:00
|
|
|
]
|
2019-01-06 13:09:45 +01:00
|
|
|
},
|
|
|
|
output: {
|
2019-08-16 18:45:11 +02:00
|
|
|
path: path.resolve('.', 'tmp'),
|
|
|
|
filename: 'js/[name].js'
|
2019-01-06 13:09:45 +01:00
|
|
|
},
|
|
|
|
target: 'web',
|
|
|
|
performance: {
|
|
|
|
hints: false
|
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
colors: false,
|
|
|
|
modules: true,
|
|
|
|
reasons: true
|
|
|
|
},
|
|
|
|
progress: false,
|
|
|
|
failOnError: true,
|
|
|
|
resolve: {
|
2019-08-16 18:45:11 +02:00
|
|
|
modules: [
|
|
|
|
path.join(__dirname, 'app/scripts'),
|
|
|
|
path.join(__dirname, 'app/styles'),
|
|
|
|
path.join(__dirname, 'node_modules')
|
|
|
|
],
|
2019-01-06 13:09:45 +01:00
|
|
|
alias: {
|
2019-09-13 23:25:57 +02:00
|
|
|
'babel-helpers': path.join(__dirname, 'app/lib/babel-helpers.js'),
|
2019-08-16 18:45:11 +02:00
|
|
|
backbone: `backbone/backbone${devMode ? '-min' : ''}.js`,
|
|
|
|
underscore: `underscore/underscore${devMode ? '-min' : ''}.js`,
|
|
|
|
_: `underscore/underscore${devMode ? '-min' : ''}.js`,
|
|
|
|
jquery: `jquery/dist/jquery${devMode ? '.min' : ''}.js`,
|
2019-01-06 13:09:45 +01:00
|
|
|
kdbxweb: 'kdbxweb/dist/kdbxweb.js',
|
2019-08-16 18:45:11 +02:00
|
|
|
baron: `baron/baron${devMode ? '.min' : ''}.js`,
|
|
|
|
qrcode: `jsqrcode/dist/qrcode${devMode ? '.min' : ''}.js`,
|
2019-09-08 09:55:46 +02:00
|
|
|
argon2: 'argon2-browser/dist/argon2.js',
|
2019-09-14 22:14:44 +02:00
|
|
|
marked: devMode ? 'marked/lib/marked.js' : 'marked/marked.min.js',
|
2019-09-14 22:12:02 +02:00
|
|
|
dompurify: `dompurify/dist/purify${devMode ? '.min' : ''}.js`,
|
2019-01-06 13:09:45 +01:00
|
|
|
hbs: 'handlebars/runtime.js',
|
|
|
|
'argon2-wasm': 'argon2-browser/dist/argon2.wasm',
|
2019-08-18 07:58:23 +02:00
|
|
|
templates: path.join(__dirname, 'app/templates'),
|
2019-08-18 10:17:09 +02:00
|
|
|
'public-key.pem': path.join(__dirname, 'app/resources/public-key.pem'),
|
|
|
|
'demo.kdbx': path.join(__dirname, 'app/resources/Demo.kdbx')
|
2019-01-06 13:09:45 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2019-08-16 23:05:39 +02:00
|
|
|
test: /\.hbs$/,
|
|
|
|
loader: StringReplacePlugin.replace('handlebars-loader', {
|
2019-01-06 13:09:45 +01:00
|
|
|
replacements: [{ pattern: /\r?\n\s*/g, replacement: () => '\n' }]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
2019-08-16 23:05:39 +02:00
|
|
|
test: /runtime-info\.js$/,
|
|
|
|
loader: StringReplacePlugin.replace({
|
2019-01-06 13:09:45 +01:00
|
|
|
replacements: [
|
2019-08-16 23:05:39 +02:00
|
|
|
{
|
|
|
|
pattern: /@@VERSION/g,
|
2019-08-18 08:05:38 +02:00
|
|
|
replacement: () =>
|
|
|
|
pkg.version + (grunt.option('beta') ? '-beta' : '')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: /@@BETA/g,
|
|
|
|
replacement: () => (grunt.option('beta') ? '1' : '')
|
2019-08-16 23:05:39 +02:00
|
|
|
},
|
2019-01-06 13:09:45 +01:00
|
|
|
{ pattern: /@@DATE/g, replacement: () => dt },
|
2019-08-16 23:05:39 +02:00
|
|
|
{
|
|
|
|
pattern: /@@COMMIT/g,
|
2019-08-18 08:05:38 +02:00
|
|
|
replacement: () =>
|
|
|
|
grunt.config.get('gitinfo.local.branch.current.shortSHA')
|
2019-08-16 23:05:39 +02:00
|
|
|
}
|
2019-01-06 13:09:45 +01:00
|
|
|
]
|
|
|
|
})
|
|
|
|
},
|
2019-08-18 08:05:38 +02:00
|
|
|
{
|
|
|
|
test: /baron(\.min)?\.js$/,
|
|
|
|
loader: 'exports-loader?baron; delete window.baron;'
|
|
|
|
},
|
2019-09-13 23:25:57 +02:00
|
|
|
{
|
|
|
|
test: /babel-helpers\.js$/,
|
|
|
|
loader: 'exports-loader?global.babelHelpers; delete global.babelHelpers'
|
|
|
|
},
|
2019-08-16 23:05:39 +02:00
|
|
|
{ test: /pikaday\.js$/, loader: 'uglify-loader' },
|
|
|
|
{ test: /handlebars/, loader: 'strip-sourcemap-loader' },
|
2019-01-06 13:09:45 +01:00
|
|
|
{
|
2019-08-16 23:05:39 +02:00
|
|
|
test: /\.js$/,
|
2019-09-13 23:25:57 +02:00
|
|
|
exclude: /(node_modules|babel-helpers\.js)/,
|
2019-08-16 23:05:39 +02:00
|
|
|
loader: 'babel-loader',
|
2019-09-13 20:34:52 +02:00
|
|
|
query: { cacheDirectory: true }
|
2019-01-06 13:09:45 +01:00
|
|
|
},
|
2019-08-16 23:05:39 +02:00
|
|
|
{ test: /argon2\.wasm/, type: 'javascript/auto', loader: 'base64-loader' },
|
|
|
|
{ test: /argon2(\.min)?\.js/, loader: 'raw-loader' },
|
2019-08-16 18:45:11 +02:00
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{ loader: 'css-loader', options: { sourceMap: devMode } },
|
|
|
|
{ loader: 'sass-loader', options: { sourceMap: devMode } }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /fonts\/.*\.(woff2|ttf|eot|svg)/,
|
2019-08-16 22:04:29 +02:00
|
|
|
use: ['url-loader', 'ignore-loader']
|
2019-08-16 18:45:11 +02:00
|
|
|
},
|
2019-08-18 07:58:23 +02:00
|
|
|
{ test: /\.woff$/, loader: 'url-loader' },
|
2019-08-18 10:17:09 +02:00
|
|
|
{ test: /\.pem$/, loader: 'raw-loader' },
|
|
|
|
{ test: /\.kdbx$/, loader: 'base64-loader' }
|
2019-01-06 13:09:45 +01:00
|
|
|
]
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
runtimeChunk: 'single',
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
vendor: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: 'vendor',
|
|
|
|
chunks: 'all'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
cache: true,
|
|
|
|
parallel: true
|
|
|
|
}),
|
2019-08-16 18:45:11 +02:00
|
|
|
new OptimizeCSSAssetsPlugin({
|
|
|
|
cssProcessorPluginOptions: {
|
|
|
|
preset: ['default', { discardComments: { removeAll: true } }]
|
|
|
|
}
|
|
|
|
}),
|
2019-01-06 13:09:45 +01:00
|
|
|
new BundleAnalyzerPlugin({
|
|
|
|
openAnalyzer: false,
|
|
|
|
analyzerMode: 'static',
|
2019-08-16 18:45:11 +02:00
|
|
|
reportFilename: 'stats/analyzer_report.html',
|
2019-01-06 13:09:45 +01:00
|
|
|
generateStatsFile: true,
|
2019-08-16 18:45:11 +02:00
|
|
|
statsFilename: 'stats/stats.json'
|
2019-01-06 13:09:45 +01:00
|
|
|
})
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
2019-08-16 23:05:39 +02:00
|
|
|
new webpack.BannerPlugin(
|
|
|
|
'keeweb v' +
|
|
|
|
pkg.version +
|
|
|
|
', (c) ' +
|
|
|
|
year +
|
|
|
|
' ' +
|
|
|
|
pkg.author.name +
|
|
|
|
', opensource.org/licenses/' +
|
|
|
|
pkg.license
|
|
|
|
),
|
2019-09-13 23:25:57 +02:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
_: 'underscore',
|
|
|
|
$: 'jquery',
|
|
|
|
babelHelpers: 'babel-helpers'
|
|
|
|
}),
|
2019-01-06 13:09:45 +01:00
|
|
|
new webpack.IgnorePlugin(/^(moment)$/),
|
2019-08-16 18:45:11 +02:00
|
|
|
new StringReplacePlugin(),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'css/[name].css'
|
|
|
|
})
|
2019-01-06 13:09:45 +01:00
|
|
|
],
|
|
|
|
node: {
|
|
|
|
console: false,
|
|
|
|
process: false,
|
|
|
|
crypto: false,
|
|
|
|
Buffer: false,
|
|
|
|
__filename: false,
|
|
|
|
__dirname: false,
|
|
|
|
fs: false,
|
|
|
|
setImmediate: false,
|
|
|
|
path: false
|
|
|
|
},
|
|
|
|
externals: {
|
|
|
|
xmldom: 'null',
|
|
|
|
crypto: 'null',
|
|
|
|
fs: 'null',
|
|
|
|
path: 'null'
|
2019-08-16 18:45:11 +02:00
|
|
|
},
|
|
|
|
devtool: devMode ? 'source-map' : undefined
|
2019-01-06 13:09:45 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.config = config;
|