From 85f78257eded9a0b17d8566121e9bb11ad23072b Mon Sep 17 00:00:00 2001 From: antelle Date: Sun, 6 Jan 2019 13:09:45 +0100 Subject: [PATCH] webpack 4 --- Gruntfile.js | 151 +- app/index.html | 1 + grunt/lib/sign.js | 33 - grunt/tasks/grunt-codesign.js | 31 - grunt/tasks/grunt-nsis.js | 38 - grunt/tasks/grunt-sign-archive.js | 26 - grunt/tasks/grunt-sign-desktop-files.js | 42 - grunt/tasks/grunt-sign-dist.js | 36 - grunt/tasks/grunt-sign-exe.js | 101 - grunt/tasks/grunt-sign-html.js | 32 - grunt/tasks/grunt-validate-desktop-update.js | 54 - package-lock.json | 7571 ++++++++---------- package.json | 24 +- webpack.config.js | 156 + 14 files changed, 3367 insertions(+), 4929 deletions(-) delete mode 100644 grunt/lib/sign.js delete mode 100644 grunt/tasks/grunt-codesign.js delete mode 100644 grunt/tasks/grunt-nsis.js delete mode 100644 grunt/tasks/grunt-sign-archive.js delete mode 100644 grunt/tasks/grunt-sign-desktop-files.js delete mode 100644 grunt/tasks/grunt-sign-dist.js delete mode 100644 grunt/tasks/grunt-sign-exe.js delete mode 100644 grunt/tasks/grunt-sign-html.js delete mode 100644 grunt/tasks/grunt-validate-desktop-update.js create mode 100644 webpack.config.js diff --git a/Gruntfile.js b/Gruntfile.js index b4ddb36c..1646b23a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,153 +1,26 @@ /* 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'); - const webpack = require('webpack'); - const pkg = require('./package.json'); - const dt = new Date().toISOString().replace(/T.*/, ''); + grunt.loadTasks('build/tasks'); + + 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.devDependencies['electron'].replace(/^\D/, ''); - 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 'Bad font rule: ' + rule.toString(); - } - const value = fontFamily.value.replace(/["']/g, ''); - const fontFiles = { - FontAwesome: 'fontawesome-webfont.woff' - }; - const fontFile = fontFiles[value]; - if (!fontFile) { - throw 'Unsupported font ' + value + ': ' + rule.toString(); - } - const data = fs.readFileSync('tmp/fonts/' + fontFile, 'base64'); - const src = 'url(data:application/font-woff;charset=utf-8;base64,{data}) format(\'woff\')' - .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: /\.js$/, exclude: /(node_modules)/, 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('keeweb v' + pkg.version + ', (c) ' + year + ' ' + pkg.author.name + - ', opensource.org/licenses/' + pkg.license), - 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' - } - }; - - 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 electronVersion = pkg.dependencies.electron.replace(/^\D/, ''); grunt.initConfig({ gitinfo: { @@ -285,7 +158,7 @@ module.exports = function(grunt) { postcss: { options: { processors: [ - replaceFont, + postCssReplaceFont, require('cssnano')({discardComments: {removeAll: true}}) ] }, @@ -340,11 +213,11 @@ module.exports = function(grunt) { } }, webpack: { - js: webpackConfig + js: webpackConfig.config(grunt, date) }, 'webpack-dev-server': { options: { - webpack: webpackDevConfig, + webpack: webpackConfig.devServerConfig(grunt, date), publicPath: '/tmp/js', progress: false }, diff --git a/app/index.html b/app/index.html index 3a93765d..d4a2f934 100644 --- a/app/index.html +++ b/app/index.html @@ -19,6 +19,7 @@ +