From 21706927f75e1176e7fdd9c9758eb4dd45d15596 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Jan 2018 12:47:00 +0100 Subject: [PATCH] WebPack? How does that work? Signed-off-by: Joas Schilling --- .gitignore | 4 +++ js/app.js | 3 ++ js/components/notification.js | 3 ++ js/components/root.js | 2 ++ js/merged.json | 7 ---- js/webpack.config.js | 66 +++++++++++++++++++++++++++++++++++ lib/AppInfo/Application.php | 6 ---- package.json | 41 ++++++++++++++++++++++ 8 files changed, 119 insertions(+), 13 deletions(-) delete mode 100644 js/merged.json create mode 100644 js/webpack.config.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 57a29e993..7c9b9a5b1 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,10 @@ nbproject .well-known /.buildpath +# WebPack +/node_modules +/js/merged.js* + # Tests - auto-generated files /tests/Unit/coverage* /tests/Unit/clover.xml diff --git a/js/app.js b/js/app.js index e1f97cf87..d62ef9895 100644 --- a/js/app.js +++ b/js/app.js @@ -9,6 +9,9 @@ * later. See the COPYING file. */ +import Vue from 'vue'; +require('./components/root'); + (function(OC, OCA, $, _) { OCA.Notifications = OCA.Notifications || {}; diff --git a/js/components/notification.js b/js/components/notification.js index fc4ff0bec..3aa420b9f 100644 --- a/js/components/notification.js +++ b/js/components/notification.js @@ -7,6 +7,9 @@ * later. See the COPYING file. */ +require('./action'); +require('../richObjectStringParser'); + (function(OC, OCA, $) { OCA.Notifications = OCA.Notifications || {}; OCA.Notifications.Components = OCA.Notifications.Components || {}; diff --git a/js/components/root.js b/js/components/root.js index 08d087cc1..abd2cccbd 100644 --- a/js/components/root.js +++ b/js/components/root.js @@ -7,6 +7,8 @@ * later. See the COPYING file. */ +require('./notification'); + (function(OC, OCA, $) { OCA.Notifications = OCA.Notifications || {}; OCA.Notifications.Components = OCA.Notifications.Components || {}; diff --git a/js/merged.json b/js/merged.json deleted file mode 100644 index fe6ff81a5..000000000 --- a/js/merged.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - "components/action.js", - "components/notification.js", - "components/root.js", - "app.js", - "richObjectStringParser.js" -] diff --git a/js/webpack.config.js b/js/webpack.config.js new file mode 100644 index 000000000..d2d0f0c16 --- /dev/null +++ b/js/webpack.config.js @@ -0,0 +1,66 @@ +var path = require('path'); +var webpack = require('webpack'); + +module.exports = { + entry: './js/app.js', + output: { + path: path.resolve(__dirname, '.'), + publicPath: '/', + filename: 'merged.js' + }, + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue-loader', + options: { + loaders: { + } + // other vue-loader options go here + } + }, + { + test: /\.js$/, + loader: 'babel-loader', + exclude: /node_modules/ + }, + { + test: /\.(png|jpg|gif|svg)$/, + loader: 'file-loader', + options: { + name: '[name].[ext]?[hash]' + } + } + ] + }, + resolve: { + alias: { + 'vue$': 'vue/dist/vue.esm.js' + } + }, + performance: { + hints: false + }, + devtool: '#eval-source-map' +}; + +if (process.env.NODE_ENV === 'production') { + module.exports.devtool = '#source-map'; + // http://vue-loader.vuejs.org/en/workflow/production.html + module.exports.plugins = (module.exports.plugins || []).concat([ + new webpack.DefinePlugin({ + 'process.env': { + NODE_ENV: '"production"' + } + }), + new webpack.optimize.UglifyJsPlugin({ + sourceMap: true, + compress: { + warnings: false + } + }), + new webpack.LoaderOptionsPlugin({ + minimize: true + }) + ]); +} diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 0666b0521..b01745314 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -63,12 +63,6 @@ protected function registerUserInterface() { && substr($request->getPathInfo(), 0, strlen('/s/')) !== '/s/' && substr($request->getPathInfo(), 0, strlen('/login/')) !== '/login/') { - if (\OC::$server->getConfig()->getSystemValue('debug', false)) { - Util::addScript('notifications', 'vue'); - } else { - Util::addScript('notifications', 'vue.min'); - } - Util::addScript('notifications', 'merged'); Util::addStyle('notifications', 'styles'); } diff --git a/package.json b/package.json new file mode 100644 index 000000000..0bf6bb796 --- /dev/null +++ b/package.json @@ -0,0 +1,41 @@ +{ + "name": "notifications", + "version": "2.2.0", + "description": "This app provides a backend and frontend for the notification API available in Nextcloud.", + "main": "index.js", + "directories": { + "lib": "lib", + "test": "tests" + }, + "scripts": { + "dev": "cross-env NODE_ENV=development webpack --progress --hot --config js/webpack.config.js --watch", + "build": "cross-env NODE_ENV=production webpack --progress --hide-modules --config js/webpack.config.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/nextcloud/notifications.git" + }, + "author": "Joas Schilling", + "license": "AGPL-3.0", + "bugs": { + "url": "https://github.com/nextcloud/notifications/issues" + }, + "homepage": "https://github.com/nextcloud/notifications#readme", + "dependencies": { + "vue": "^2.5.13" + }, + "devDependencies": { + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-preset-env": "^1.6.0", + "cross-env": "^5.1.3", + "css-loader": "^0.28.8", + "file-loader": "^1.1.6", + "vue-hot-reload-api": "^2.2.4", + "vue-loader": "^13.7.0", + "vue-template-compiler": "^2.5.13", + "webpack": "^3.6.0", + "webpack-dev-server": "^2.11.0" + } +}