Commit 0b6de382 authored by adietmue's avatar adietmue
Browse files

Add top-level configs and clean up webpack config

parent 7ca47bb3
......@@ -15,4 +15,10 @@ module.exports = {
'prettier/prettier': 'error',
},
plugins: ['prettier'],
// Activate the resolver plugin, required to recognize the 'config' resolver
settings: {
'import/resolver': {
webpack: {},
},
},
};
/**
* Url used for calls to the AMIV API
*/
export const apiUrl = 'https://api.amiv.ethz.ch';
/**
* Enable/Disable verbose output.
*/
export const verbose = false;
/**
* Url used to send error logs
*/
export const sentryUrl = 'https://b634a14e6c5d4ebf8c319763f30ff87d:e494d61191434d11981838b1d11d14c1@sentry.amiv.ethz.ch/4';
\ No newline at end of file
// src/index.js
import m from 'mithril';
import Raven from 'raven-js';
import { verbose, sentryUrl } from 'config';
import { loadLanguage, currentLanguage, changeLanguage, isLanguageValid } from './models/language';
import { verbose, sentryUrl } from './models/config';
import { Error404, Error401 } from './views/errors';
import { isLoggedIn } from './models/auth';
import studydocList from './views/studydocs/studydocList';
......
import m from 'mithril';
import { apiUrl } from './config';
import { apiUrl } from 'config';
import { log } from './log';
const APISession = {
......
import m from 'mithril';
import { apiUrl } from './config';
import { apiUrl } from 'config';
import { getToken, getUserId, isLoggedIn } from './auth';
import { currentLanguage } from './language';
......
import m from 'mithril';
import { apiUrl } from './config';
import { apiUrl } from 'config';
import { getToken, getUserId } from './auth';
import { error } from './log';
......
import m from 'mithril';
import { apiUrl } from './config';
import { apiUrl } from 'config';
import { getToken } from './auth';
import { currentLanguage } from './language';
......
import { verbose } from './config';
import { verbose } from 'config';
/**
* Print `log message` to the console if verbose is enabled.
......
import m from 'mithril';
import { apiUrl } from './config';
import { apiUrl } from 'config';
import { getToken } from './auth';
let querySaved = {};
......
import m from 'mithril';
import { apiUrl } from './config';
import { apiUrl } from 'config';
import { getToken, getUserId } from './auth';
import { log, error } from './log';
......
import m from 'mithril';
import { apiUrl } from '../models/config';
import { apiUrl } from 'config';
import * as events from '../models/events';
import { i18n } from '../models/language';
......
import m from 'mithril';
import marked from 'marked';
import { apiUrl } from '../../models/config';
import { apiUrl } from 'config';
import * as jobs from '../../models/joboffers';
import { log } from '../../models/log';
......
import m from 'mithril';
import { apiUrl } from '../../models/config';
import { apiUrl } from 'config';
import * as jobs from '../../models/joboffers';
import { currentLanguage } from '../../models/language';
......
import m from 'mithril';
import { apiUrl } from 'config';
import * as studydocs from '../../models/studydocs';
import { apiUrl } from '../../models/config';
import { Button, Checkbox, TextField, Dropdown } from '../../components';
const tableHeadings = ['title', 'type'];
......
......@@ -26,7 +26,7 @@ const config = {
use: [
{
loader: 'babel-loader',
options: { presets: ['env'] },
options: { presets: [['env', { targets: "last 2 years"}]] },
},
],
},
......@@ -122,6 +122,14 @@ const config = {
],
},
// Dynamically include config
resolve: {
alias: {
config: `${__dirname}/config.js`,
},
},
devtool: 'eval-source-map', // Default development sourcemap
};
......
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const config = {
context: `${__dirname}/src`, // `__dirname` is root of project and `src` is source
// Start with dev config
const config = require('./webpack.config.js');
entry: './index.js',
// Remove development server and code map
config.devServer = undefined;
config.devtool = '';
output: {
path: `${__dirname}/dist`, // `dist` is the destination
filename: 'bundle.js',
},
// Add optimization plugins
config.plugins = [
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
];
module: {
rules: [
{
test: /\.js$/, // Check for all js files
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: { presets: ['env'] },
},
],
},
{
test: /src\/views\/companies\/markdown\/[a-zA-Z\d-]{3,}\.[a-z]{2}\.md$/, // Check for all .md files in /companies/markdown
use: [
{
loader: 'file-loader', // Writes the generated HTML to a file
options: {
name: '[name].html',
outputPath: 'companies/',
publicPath: 'dist/companies/',
},
},
{
loader: 'markdown-loader', // Converts Markdown to HTML
},
{
loader: 'string-replace-loader', // Adds /#! prefix to local urls
options: {
search: '\[(.*)\]\((\/(?!dist).*)\)',
replace: '(/#!$1',
flags: 'g',
},
},
],
},
{
test: /src\/views\/amiv\/markdown\/[a-zA-Z\d-]{3,}\.[a-z]{2}\.md$/, // Check for all .md files in /amiv/markdown
use: [
{
loader: 'file-loader', // Writes the generated HTML to a file
options: {
name: '[name].html',
outputPath: 'amiv/',
publicPath: 'dist/amiv/',
},
},
{
loader: 'markdown-loader', // Converts Markdown to HTML
},
{
loader: 'string-replace-loader', // Adds /#! prefix to local urls
options: {
search: '\[(.*)\]\((\/(?!dist).*)\)',
replace: '(/#!$1',
flags: 'g',
},
},
],
},
{
test: /src\/views\/amiv\/html\/[a-zA-Z\d-]{3,}\.html$/, // Check for all .html files in /amiv/html
use: [
{
loader: 'file-loader', // Writes the generated HTML to a file
options: {
name: '[name].html',
outputPath: 'amiv/',
publicPath: 'dist/amiv/',
},
},
],
},
{
test: /src\/views\/amiv\/images\/[a-zA-Z\d\/]+\.(png|jp(e*)g|svg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8000, // Convert images < 8kb to base64 strings
name: '[name].[ext]',
outputPath: 'amiv/',
publicPath: 'dist/amiv/',
},
},
],
},
{
test: /\.less$/,
use: [
{
loader: 'style-loader', // creates style nodes from JS strings
},
{
loader: 'css-loader', // translates CSS into CommonJS
},
{
loader: 'less-loader', // compiles Less to CSS
},
],
},
],
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
],
devtool: '', // No source map for production build
};
// Replace development with production config
config.resolve.alias.config = `${__dirname}/config.prod.js`;
module.exports = config;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment