From fffa1192d6ecf37297fe0c10c647e3713cdb84a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Mon, 12 Dec 2016 16:27:33 +0000 Subject: [PATCH] fix @ui require --- frontend/package.json | 3 +- frontend/webpack/base.js | 51 ++++++++++++++++++++++++--------- frontend/webpack/development.js | 2 +- frontend/webpack/paths.js | 17 +++++++++++ frontend/webpack/production.js | 3 -- frontend/webpack/test.js | 35 ++-------------------- frontend/yarn.lock | 15 ++++++++-- 7 files changed, 74 insertions(+), 52 deletions(-) create mode 100644 frontend/webpack/paths.js diff --git a/frontend/package.json b/frontend/package.json index b411e88a..83cf8597 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -42,7 +42,8 @@ "redux-promise-middleware": "^4.2.0", "redux-thunk": "^2.1.0", "st": "^1.2.0", - "styled-components": "^1.1.3" + "styled-components": "^1.1.3", + "url-loader": "^0.5.7" }, "devDependencies": { "ava": "^0.17.0", diff --git a/frontend/webpack/base.js b/frontend/webpack/base.js index a12a3b2d..53a8342e 100644 --- a/frontend/webpack/base.js +++ b/frontend/webpack/base.js @@ -2,26 +2,34 @@ const path = require('path'); const fs = require('fs'); const plugins = require('./plugins'); -const CONTEXT = path.join(__dirname, '../src'); -const STATIC = path.join(__dirname, '../static'); -const ROOT = path.join(__dirname, '../..'); +const paths = require('./paths'); + +const { + ROOT, + MODULES, + FRONTEND, + UI, + STATIC +} = paths; module.exports = { - context: CONTEXT, + context: ROOT, + entry: `./${path.relative(ROOT, path.join(FRONTEND, 'index.js'))}`, resolve: { - modules: [ - ROOT, - 'node_modules' - ], - alias: fs.readdirSync(CONTEXT) - .map((name) => path.join(CONTEXT, name)) + modules: MODULES, + 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': CONTEXT + '@root': FRONTEND, + '@ui': UI }) }, + resolveLoader: { + modules: MODULES + }, output: { path: STATIC, publicPath: '/static/', @@ -36,13 +44,30 @@ module.exports = { loaders: [{ test: /js?$/, exclude: /node_modules/, - include: [CONTEXT], + include: [ + FRONTEND, + UI + ], loaders: ['babel-loader'] }, { test: /\.json?$/, exclude: /node_modules/, - include: [CONTEXT], + include: [ + FRONTEND, + UI + ], loaders: ['json-loader'] + }, { + test: /\.png$/, + exclude: /node_modules/, + include: [ + FRONTEND, + UI + ], + loader: 'url-loader', + query: { + mimetype: 'image/png' + } }] } }; diff --git a/frontend/webpack/development.js b/frontend/webpack/development.js index 2ab2ac5b..86eaeaed 100644 --- a/frontend/webpack/development.js +++ b/frontend/webpack/development.js @@ -21,7 +21,7 @@ module.exports = Object.assign(base, { 'react-hot-loader/patch', 'webpack-dev-server/client?http://localhost:8080', 'webpack/hot/only-dev-server', - './index.js' + base.entry ], plugins: base.plugins.concat([ plugins['named-modules'], diff --git a/frontend/webpack/paths.js b/frontend/webpack/paths.js new file mode 100644 index 00000000..cfd16c21 --- /dev/null +++ b/frontend/webpack/paths.js @@ -0,0 +1,17 @@ +const path = require('path'); + +const ROOT = path.join(__dirname, '../..'); +const UI = path.join(ROOT, 'ui'); +const FRONTEND = path.join(ROOT, 'frontend'); + +module.exports = { + ROOT, + MODULES: [ + path.join(FRONTEND, 'node_modules'), + path.join(UI, 'node_modules'), + 'node_modules' + ], + FRONTEND: path.join(FRONTEND, 'src'), + UI: path.join(UI, 'src'), + STATIC: path.join(FRONTEND, 'static') +}; diff --git a/frontend/webpack/production.js b/frontend/webpack/production.js index 0ae710f0..48df216c 100644 --- a/frontend/webpack/production.js +++ b/frontend/webpack/production.js @@ -4,9 +4,6 @@ const base = require('./base'); module.exports = Object.assign(base, { devtool: 'hidden-source-map', - entry: [ - './index.js' - ], plugins: base.plugins.concat([ // plugins['occurrence-order'], // plugins['aggressive-merging'], diff --git a/frontend/webpack/test.js b/frontend/webpack/test.js index 534441ed..13710f53 100644 --- a/frontend/webpack/test.js +++ b/frontend/webpack/test.js @@ -1,25 +1,8 @@ -const path = require('path'); -const fs = require('fs'); - +const base = require('./base'); const plugins = require('./plugins'); -const CONTEXT = path.join(__dirname, '../src'); -const ROOT = path.join(__dirname, '../..'); module.exports = { - resolve: { - modules: [ - ROOT, - 'node_modules' - ], - alias: fs.readdirSync(CONTEXT) - .map((name) => path.join(CONTEXT, name)) - .filter((fullpath) => fs.statSync(fullpath).isDirectory()) - .reduce((aliases, fullpath) => Object.assign(aliases, { - [`@${path.basename(fullpath)}`]: fullpath - }), { - '@root': CONTEXT - }) - }, + resolve: base.resolve, output: { libraryTarget: 'commonjs2' }, @@ -28,17 +11,5 @@ module.exports = { plugins['no-errors'], plugins['define'] ], - module: { - loaders: [{ - test: /js?$/, - exclude: /node_modules/, - include: [CONTEXT], - loaders: ['babel-loader'] - }, { - test: /\.json?$/, - exclude: /node_modules/, - include: [CONTEXT], - loaders: ['json-loader'] - }] - } + module: base.module }; diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 344acd3f..d7e572cc 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -3360,7 +3360,7 @@ loader-runner@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.2.0.tgz#824c1b699c4e7a2b6501b85902d5b862bf45b3fa" -loader-utils@^0.2.11, loader-utils@^0.2.16: +loader-utils@^0.2.11, loader-utils@^0.2.16, loader-utils@0.2.x: version "0.2.16" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz#f08632066ed8282835dff88dfb52704765adee6d" dependencies: @@ -3605,6 +3605,10 @@ mime@^1.3.4, mime@~1.3.4, mime@1.3.4: version "1.3.4" resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53" +mime@1.2.x: + version "1.2.11" + resolved "https://registry.yarnpkg.com/mime/-/mime-1.2.11.tgz#58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10" + min-document@^2.19.0: version "2.19.0" resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685" @@ -5062,7 +5066,7 @@ strip-json-comments@~1.0.1, strip-json-comments@~1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91" -styled-components: +styled-components@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-1.1.3.tgz#9f5b19cff1b53e9063fdf82ccdf024dfd4d68d21" dependencies: @@ -5333,6 +5337,13 @@ upper-case@^1.1.1: version "1.1.3" resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-1.1.3.tgz#f6b4501c2ec4cdd26ba78be7222961de77621598" +url-loader@^0.5.7: + version "0.5.7" + resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-0.5.7.tgz#67e8779759f8000da74994906680c943a9b0925d" + dependencies: + loader-utils "0.2.x" + mime "1.2.x" + url-parse-lax@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/url-parse-lax/-/url-parse-lax-1.0.0.tgz#7af8f303645e9bd79a272e7a14ac68bc0609da73"