From 80a417d33f35c1250373f91fbd05b5c2be17e3f6 Mon Sep 17 00:00:00 2001 From: JUDIT GRESKOVITS Date: Tue, 23 May 2017 14:30:14 +0100 Subject: [PATCH] Tidy --- frontend/scripts/webpack.config.dev.js | 136 ++++++++++--------------- 1 file changed, 53 insertions(+), 83 deletions(-) diff --git a/frontend/scripts/webpack.config.dev.js b/frontend/scripts/webpack.config.dev.js index 42f430bd..f26bcd21 100644 --- a/frontend/scripts/webpack.config.dev.js +++ b/frontend/scripts/webpack.config.dev.js @@ -1,13 +1,3 @@ -// @remove-on-eject-begin -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -// @remove-on-eject-end 'use strict'; const fs = require('fs'); @@ -26,86 +16,66 @@ const MODULES = [ path.join(UI_ROOT, 'node_modules'), 'node_modules' ]; -const FRONTEND = path.join(FRONTEND_ROOT, 'src'); // duplicate +const FRONTEND = path.join(FRONTEND_ROOT, 'src'); const UI = process.env.NODE_ENV === 'production' ? path.join(FRONTEND_ROOT, 'node_modules', '@tomgco/joyent-portal-ui', 'dist') - : path.join(UI_ROOT, 'src'); // also duplicate + : path.join(UI_ROOT, 'src'); const STATIC = path.join(FRONTEND_ROOT, 'static'); const ESLINT = path.join(__dirname, '.eslintrc'); -// module.exports = originalConfig; +const rules = originalConfig.module.rules.reduce((loaders, loader, index) => { + if(loader.test === /\.(js|jsx)$/) { + loaders.push({ + test: loader.test, + include: [loader.include, UI], + loader: loader.loader, + options: { + babelrc: false, + presets: [require.resolve('babel-preset-react-app')], + plugins: [['inline-react-svg', { + ignorePattern: 'libre-franklin' + }]], + cacheDirectory: true + } + }) + } + else if(index === 1) { + loaders.push({ + exclude: loader.exclude.concat([/\.(graphql|gql)$/]), + loader: loader.loader, + options: loader.options + }) + } + else if(loader.include) { + loaders.push(Object.assign({}, loader, {include: [loader.include, UI]})); + } + else { + loaders.push(loader); + } + return loaders; +}, []); -// module.exports = function() { +rules.push({ + test: /\.(graphql|gql)$/, + exclude: /node_modules/, + loader: require.resolve('graphql-tag/loader') +}); - console.log('originalConfig = ', originalConfig); - // return originalConfig; +const aliases = Object.assign({}, originalConfig.resolve.alias, fs.readdirSync(FRONTEND) + .map((name) => path.join(FRONTEND, name)) + .filter((fullpath) => fs.statSync(fullpath).isDirectory()) + .reduce((aliases, fullpath) => Object.assign(aliases, { + [`@${path.basename(fullpath)}`]: fullpath + }), { + '@root': FRONTEND, + '@ui': UI + })); - // config.module.rules[1].exclude.push(/\.(graphql|gql)$/); +const resolveModules = originalConfig.resolve.modules.concat(MODULES); - const rules = originalConfig.module.rules.reduce((loaders, loader, index) => { - if(loader.test === /\.(js|jsx)$/) { - loaders.push({ - test: loader.test, - include: [loader.include, UI], - loader: loader.loader, - options: { - babelrc: false, - presets: [require.resolve('babel-preset-react-app')], - plugins: [['inline-react-svg', { - ignorePattern: 'libre-franklin' - }]], - cacheDirectory: true - } - }) - } - else if(index === 1) { - loaders.push({ - exclude: loader.exclude.concat([/\.(graphql|gql)$/]), - loader: loader.loader, - options: loader.options - }) - } - else if(loader.include) { - loaders.push(Object.assign({}, loader, {include: [loader.include, UI]})); - } - else { - loaders.push(loader); - } - return loaders; - }, []); +originalConfig.module.rules = rules; +originalConfig.resolve.alias = aliases; +originalConfig.resolve.modules = resolveModules; +originalConfig.resolve.plugins = []; - rules.push({ - test: /\.(graphql|gql)$/, - exclude: /node_modules/, - loader: require.resolve('graphql-tag/loader') - }); - - const aliases = Object.assign({}, originalConfig.resolve.alias, fs.readdirSync(FRONTEND) - .map((name) => path.join(FRONTEND, name)) - .filter((fullpath) => fs.statSync(fullpath).isDirectory()) - .reduce((aliases, fullpath) => Object.assign(aliases, { - [`@${path.basename(fullpath)}`]: fullpath - }), { - '@root': FRONTEND, - '@ui': UI - })); - - const resolveModules = originalConfig.resolve.modules.concat(MODULES); - - originalConfig.module.rules = rules; - originalConfig.resolve.alias = aliases; - originalConfig.resolve.modules = resolveModules; - originalConfig.resolve.plugins = []; - - module.exports = originalConfig; - - // return originalConfig; - - // resolves - // config.resolveLoader.modules = MODULES; - - // config.resolve.modules = MODULES; - - // set rules and return - -// } +module.exports = originalConfig;