Skip to content

Commit

Permalink
webpack 4
Browse files Browse the repository at this point in the history
Signed-off-by: luckyrat <luckyrat@musites.com>
  • Loading branch information
antelle authored and luckyrat committed Feb 24, 2019
1 parent cbeb394 commit 02c1c8b
Show file tree
Hide file tree
Showing 8 changed files with 2,377 additions and 2,692 deletions.
172 changes: 15 additions & 157 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,169 +1,27 @@
/* eslint-env node */

const fs = require('fs');
const path = require('path');

const sass = require('node-sass');

const StringReplacePlugin = require('string-replace-webpack-plugin');
const StatsPlugin = require('stats-webpack-plugin');
const webpackConfig = require('./webpack.config');
const postCssReplaceFont = require('./build/util/postcss-replace-font');
const pkg = require('./package.json');

module.exports = function(grunt) {
require('time-grunt')(grunt);
require('load-grunt-tasks')(grunt);
grunt.loadTasks('grunt/tasks');
grunt.loadNpmTasks('grunt-string-replace');

const webpack = require('webpack');
const pkg = require('./package.json');
const dt = new Date().toISOString().replace(/T.*/, '');
const year = new Date().getFullYear();

function replaceFont(css) {
css.walkAtRules('font-face', rule => {
const fontFamily = rule.nodes.filter(n => n.prop === 'font-family')[0];
if (!fontFamily) {
throw 'Font rule missing font-face: ' + rule.toString();
}
const value = fontFamily.value.replace(/["']/g, '');
const fontFiles = {
'Font Awesome 5 Brands': 'fa-brands-400.woff2',
'Font Awesome 5 Free': {
'400': 'fa-regular-400.woff2',
'900': 'fa-solid-900.woff2'
}
};
let fontFile = fontFiles[value];
if (!fontFile) {
throw 'Unsupported font ' + value + ': ' + rule.toString();
}
if (typeof fontFile !== 'string') {
const fontWeight = rule.nodes.filter(n => n.prop === 'font-weight')[0];
if (!fontWeight) {
throw 'Font rule missing font-weight: ' + rule.toString();
}
fontFile = fontFile[fontWeight.value];
if (!fontFile) {
throw 'Unsupported font ' + value + ': ' + rule.toString();
}
}
const data = fs.readFileSync('tmp/fonts/' + fontFile, 'base64');
const src = 'url(data:application/font-woff2;charset=utf-8;base64,{data}) format(\'woff2\')'
.replace('{data}', data);
rule.nodes = rule.nodes.filter(n => n.prop !== 'src');
rule.append({ prop: 'src', value: src });
});
}

const webpackConfig = {
entry: {
app: 'app',
vendor: ['jquery', 'underscore', 'backbone', 'kdbxweb', 'baron', 'pikaday', 'file-saver', 'jsqrcode',
'argon2-wasm', 'argon2']
},
output: {
path: path.resolve('.', 'tmp/js'),
filename: 'app.js'
},
stats: {
colors: false,
modules: true,
reasons: true
},
progress: false,
failOnError: true,
resolve: {
modules: [path.join(__dirname, 'app/scripts'), path.join(__dirname, 'node_modules')],
alias: {
backbone: 'backbone/backbone-min.js',
underscore: 'underscore/underscore-min.js',
_: 'underscore/underscore-min.js',
jquery: 'jquery/dist/jquery.min.js',
kdbxweb: 'kdbxweb/dist/kdbxweb.js',
baron: 'baron/baron.min.js',
pikaday: 'pikaday/pikaday.js',
filesaver: 'FileSaver.js/FileSaver.min.js',
qrcode: 'jsqrcode/dist/qrcode.min.js',
argon2: 'argon2-browser/dist/argon2.min.js',
hbs: 'handlebars/runtime.js',
'argon2-wasm': 'argon2-browser/dist/argon2.wasm',
templates: path.join(__dirname, 'app/templates')
}
},
module: {
loaders: [
{ test: /\.hbs$/, loader: StringReplacePlugin.replace('handlebars-loader', { replacements: [{
pattern: /\r?\n\s*/g,
replacement: function() { return '\n'; }
}]})},
{ test: /runtime-info\.js$/, loader: StringReplacePlugin.replace({ replacements: [
{
pattern: /@@VERSION/g,
replacement: function () { return pkg.version + (grunt.option('beta') ? '-beta' : ''); }
},
{ pattern: /@@BETA/g, replacement: function() { return grunt.option('beta') ? '1' : ''; } },
{ pattern: /@@DATE/g, replacement: function() { return dt; } },
{ pattern: /@@COMMIT/g, replacement: function() { return grunt.config.get('gitinfo.local.branch.current.shortSHA'); } }
]})},
{ test: /baron(\.min)?\.js$/, loader: 'exports-loader?baron; delete window.baron;' },
{ test: /pikaday\.js$/, loader: 'uglify-loader' },
{ test: /handlebars/, loader: 'strip-sourcemap-loader' },
{
test: /(kee-frontend|kprpc|kdbx-placeholders)\/dist\/.+\.js$/,
use: ['source-map-loader'],
enforce: 'pre'
},
{ test: /\.js$/, exclude: /(node_modules|kee-frontend|kprpc|kdbx-placeholders)/, loader: 'babel-loader',
query: { presets: ['es2015'], cacheDirectory: true }
},
{ test: /\.json$/, loader: 'json-loader' },
{ test: /argon2\.wasm$/, loader: 'base64-loader' },
{ test: /argon2(\.min)?\.js/, loader: 'raw-loader' },
{ test: /\.scss$/, loader: 'raw-loader' }
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', minChunks: Infinity, filename: 'vendor.js' }),
new webpack.BannerPlugin('kee vault v' + pkg.version + ', (c) ' + year + ' ' + pkg.author.name +
', AGPLv3 with supplemental terms'),
new webpack.ProvidePlugin({ _: 'underscore', $: 'jquery' }),
new webpack.IgnorePlugin(/^(moment)$/),
new StringReplacePlugin(),
new StatsPlugin('stats.json', { chunkModules: true })
],
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'
}
};
grunt.loadTasks('build/tasks');
grunt.loadNpmTasks('grunt-string-replace');

const webpackDevConfig = Object.assign({}, webpackConfig, {
resolve: Object.assign({}, webpackConfig.resolve, {
alias: Object.assign({}, webpackConfig.resolve.alias, {
backbone: 'backbone/backbone.js',
underscore: 'underscore/underscore.js',
_: 'underscore/underscore.js',
jquery: 'jquery/dist/jquery.js',
baron: 'baron/baron.js',
filesaver: 'FileSaver.js/FileSaver.js',
qrcode: 'jsqrcode/dist/qrcode.js',
argon2: 'argon2-browser/dist/argon2.js'
})
})
});
const date = new Date();
const dt = date.toISOString().replace(/T.*/, '');
const year = date.getFullYear();
const minElectronVersionForUpdate = '1.7.0';
const zipCommentPlaceholderPart = 'zip_comment_placeholder_that_will_be_replaced_with_hash';
const zipCommentPlaceholder = zipCommentPlaceholderPart + '.'.repeat(512 - zipCommentPlaceholderPart.length);
const electronVersion = pkg.dependencies.electron.replace(/^\D/, '');

grunt.initConfig({
gitinfo: {
Expand Down Expand Up @@ -265,7 +123,7 @@ module.exports = function(grunt) {
postcss: {
options: {
processors: [
replaceFont,
postCssReplaceFont,
require('cssnano')({discardComments: {removeAll: true}})
]
},
Expand All @@ -292,11 +150,11 @@ module.exports = function(grunt) {
}
},
webpack: {
js: webpackConfig
js: webpackConfig.config(grunt, date)
},
'webpack-dev-server': {
options: {
webpack: webpackDevConfig,
webpack: webpackConfig.devServerConfig(grunt, date),
contentBase: path.join(__dirname, 'tmp'),
publicPath: '/js',
progress: false,
Expand Down
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
</div>
<script src="js/vendor.js?__inline=true"></script>
<script src="js/app.js?__inline=true"></script>
<script src="js/runtime.js?__inline=true"></script>
<script>
var updateAvailableElement;
var updateAvailableRenderer;
Expand Down
33 changes: 0 additions & 33 deletions grunt/lib/sign.js

This file was deleted.

36 changes: 0 additions & 36 deletions grunt/tasks/grunt-sign-dist.js

This file was deleted.

32 changes: 0 additions & 32 deletions grunt/tasks/grunt-sign-html.js

This file was deleted.

Loading

0 comments on commit 02c1c8b

Please sign in to comment.