From d6172d4643c52c708336511d9a61cf530ecd4fec Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Tue, 25 Aug 2020 16:33:24 -0300 Subject: [PATCH] =?UTF-8?q?config=20v=C3=ADnc=20de=20backend=20e=20fronten?= =?UTF-8?q?d=20no=20mesmo=20projeto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/vue.config.js | 141 +++++++++++++++++++++++++++++++++++++++++ sapl/settings.py | 4 +- 2 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 frontend/vue.config.js diff --git a/frontend/vue.config.js b/frontend/vue.config.js new file mode 100644 index 000000000..6bb7fa658 --- /dev/null +++ b/frontend/vue.config.js @@ -0,0 +1,141 @@ +const path = require('path') +const each = require('lodash/fp/each') + +const MomentLocalesPlugin = require('moment-locales-webpack-plugin') +const BundleTrackerPlugin = require('webpack-bundle-tracker') +const CompressionPlugin = require('compression-webpack-plugin') + +class RelativeBundleTrackerPlugin extends BundleTrackerPlugin { + convertPathChunks (chunks) { + each(each(chunk => { + chunk.path = path.relative(this.options.path, chunk.path) + }))(chunks) + } + + writeOutput (compiler, contents) { + if (contents.status === 'done') { + this.convertPathChunks(contents.chunks) + } + super.writeOutput(compiler, contents) + } +} +// module.exports = RelativeBundleTrackerPlugin + +const dotenv = require('dotenv') +dotenv.config({ + path: '../sapl/.env' +}) + +var FRONTEND_CUSTOM = process.env.FRONTEND_CUSTOM === undefined ? false : process.env.FRONTEND_CUSTOM === 'True' + +var HOST_NAME = 'localhost' + +module.exports = { + runtimeCompiler: true, + publicPath: process.env.NODE_ENV === 'production' ? '/static/sapl/frontend' : `http://${HOST_NAME}:8080/`, + outputDir: FRONTEND_CUSTOM ? 'dist' : '../sapl/static/sapl/frontend', + + chainWebpack: config => { + config.plugins.delete('html') + config.plugins.delete('preload') + config.plugins.delete('prefetch') + + config + .plugin('RelativeBundleTrackerPlugin') + .use(RelativeBundleTrackerPlugin, [{ + path: '.', + filename: FRONTEND_CUSTOM ? './webpack-stats.json' : '../sapl/webpack-stats.json' + }]) + + config + .plugin('MomentLocalesPlugin') + .use(MomentLocalesPlugin, [{ + localesToKeep: ['pt-BR'] + }]) + + if (process.env.NODE_ENV === 'production') { + config.optimization.minimizer('terser').tap((args) => { + args[0].terserOptions.compress.drop_console = true + args[0].extractComments = true + args[0].cache = true + return args + }) + + config + .plugin('CompressionPlugin') + .use(CompressionPlugin, [{ + }]) + } else { + config + .devtool('source-map') + } + + config.resolve.alias + .set('__STATIC__', 'static') + + config.module + .rule('vue') + .use('vue-loader') + .loader('vue-loader') + .tap(options => { + options.transformAssetUrls = { + img: 'src', + image: 'xlink:href', + 'b-img': 'src', + 'b-img-lazy': ['src', 'blank-src'], + 'b-card': 'img-src', + 'b-card-img': 'img-src', + 'b-carousel-slide': 'img-src', + 'b-embed': 'src' + } + + return options + }) + + config.devServer + .public('') + .port(8080) + .hot(true) + .watchOptions({ + poll: true + }) + .watchContentBase(true) + .https(false) + .headers({ + 'Access-Control-Allow-Origin': '*' + }) + .contentBase([ + path.join(__dirname, 'public'), + path.join(__dirname, 'src', 'assets') + ]) + + config + .plugin('provide') + .use(require('webpack/lib/ProvidePlugin'), [{ + $: 'jquery', + jquery: 'jquery', + 'window.jQuery': 'jquery', + jQuery: 'jquery', + _: 'lodash' + }]) + + config.entryPoints.delete('app') + + config + .entry('global') + .add('./src/__global/main.js') + .end() + + config.entry('compilacao') + .add('./src/__apps/compilacao/main.js') + .end() + + config.entry('painel') + .add('./src/__apps/painel/main.js') + .end() + + config.entry('parlamentar') + .add('./src/__apps/parlamentar/main.js') + .end() + } +} diff --git a/sapl/settings.py b/sapl/settings.py index 46a39b1d5..c19ef19ea 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -276,7 +276,7 @@ WEBPACK_LOADER = { 'DEFAULT': { 'CACHE': not DEBUG, 'BUNDLE_DIR_NAME': 'sapl/static/sapl/frontend', - 'STATS_FILE': (BASE_DIR if not FRONTEND_CUSTOM else PROJECT_DIR.parent.child('sapl-frontend')).child('webpack-stats.json'), + 'STATS_FILE': (BASE_DIR if not FRONTEND_CUSTOM else PROJECT_DIR.child('frontend')).child('webpack-stats.json'), 'POLL_INTERVAL': 0.1, 'TIMEOUT': None, 'IGNORE': [r'.+\.hot-update.js', r'.+\.map'] @@ -291,7 +291,7 @@ STATICFILES_DIRS = ( ) if FRONTEND_CUSTOM: STATICFILES_DIRS = ( - PROJECT_DIR.parent.child('sapl-frontend').child('dist'), + PROJECT_DIR.child('frontend').child('dist'), ) STATICFILES_FINDERS = (