fix @ui require

This commit is contained in:
Sérgio Ramos 2016-12-12 16:27:33 +00:00
parent 52ca697962
commit fffa1192d6
7 changed files with 74 additions and 52 deletions

View File

@ -42,7 +42,8 @@
"redux-promise-middleware": "^4.2.0", "redux-promise-middleware": "^4.2.0",
"redux-thunk": "^2.1.0", "redux-thunk": "^2.1.0",
"st": "^1.2.0", "st": "^1.2.0",
"styled-components": "^1.1.3" "styled-components": "^1.1.3",
"url-loader": "^0.5.7"
}, },
"devDependencies": { "devDependencies": {
"ava": "^0.17.0", "ava": "^0.17.0",

View File

@ -2,26 +2,34 @@ const path = require('path');
const fs = require('fs'); const fs = require('fs');
const plugins = require('./plugins'); const plugins = require('./plugins');
const CONTEXT = path.join(__dirname, '../src'); const paths = require('./paths');
const STATIC = path.join(__dirname, '../static');
const ROOT = path.join(__dirname, '../..'); const {
ROOT,
MODULES,
FRONTEND,
UI,
STATIC
} = paths;
module.exports = { module.exports = {
context: CONTEXT, context: ROOT,
entry: `./${path.relative(ROOT, path.join(FRONTEND, 'index.js'))}`,
resolve: { resolve: {
modules: [ modules: MODULES,
ROOT, alias: fs.readdirSync(FRONTEND)
'node_modules' .map((name) => path.join(FRONTEND, name))
],
alias: fs.readdirSync(CONTEXT)
.map((name) => path.join(CONTEXT, name))
.filter((fullpath) => fs.statSync(fullpath).isDirectory()) .filter((fullpath) => fs.statSync(fullpath).isDirectory())
.reduce((aliases, fullpath) => Object.assign(aliases, { .reduce((aliases, fullpath) => Object.assign(aliases, {
[`@${path.basename(fullpath)}`]: fullpath [`@${path.basename(fullpath)}`]: fullpath
}), { }), {
'@root': CONTEXT '@root': FRONTEND,
'@ui': UI
}) })
}, },
resolveLoader: {
modules: MODULES
},
output: { output: {
path: STATIC, path: STATIC,
publicPath: '/static/', publicPath: '/static/',
@ -36,13 +44,30 @@ module.exports = {
loaders: [{ loaders: [{
test: /js?$/, test: /js?$/,
exclude: /node_modules/, exclude: /node_modules/,
include: [CONTEXT], include: [
FRONTEND,
UI
],
loaders: ['babel-loader'] loaders: ['babel-loader']
}, { }, {
test: /\.json?$/, test: /\.json?$/,
exclude: /node_modules/, exclude: /node_modules/,
include: [CONTEXT], include: [
FRONTEND,
UI
],
loaders: ['json-loader'] loaders: ['json-loader']
}, {
test: /\.png$/,
exclude: /node_modules/,
include: [
FRONTEND,
UI
],
loader: 'url-loader',
query: {
mimetype: 'image/png'
}
}] }]
} }
}; };

View File

@ -21,7 +21,7 @@ module.exports = Object.assign(base, {
'react-hot-loader/patch', 'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080', 'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server', 'webpack/hot/only-dev-server',
'./index.js' base.entry
], ],
plugins: base.plugins.concat([ plugins: base.plugins.concat([
plugins['named-modules'], plugins['named-modules'],

17
frontend/webpack/paths.js Normal file
View File

@ -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')
};

View File

@ -4,9 +4,6 @@ const base = require('./base');
module.exports = Object.assign(base, { module.exports = Object.assign(base, {
devtool: 'hidden-source-map', devtool: 'hidden-source-map',
entry: [
'./index.js'
],
plugins: base.plugins.concat([ plugins: base.plugins.concat([
// plugins['occurrence-order'], // plugins['occurrence-order'],
// plugins['aggressive-merging'], // plugins['aggressive-merging'],

View File

@ -1,25 +1,8 @@
const path = require('path'); const base = require('./base');
const fs = require('fs');
const plugins = require('./plugins'); const plugins = require('./plugins');
const CONTEXT = path.join(__dirname, '../src');
const ROOT = path.join(__dirname, '../..');
module.exports = { module.exports = {
resolve: { resolve: base.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
})
},
output: { output: {
libraryTarget: 'commonjs2' libraryTarget: 'commonjs2'
}, },
@ -28,17 +11,5 @@ module.exports = {
plugins['no-errors'], plugins['no-errors'],
plugins['define'] plugins['define']
], ],
module: { module: base.module
loaders: [{
test: /js?$/,
exclude: /node_modules/,
include: [CONTEXT],
loaders: ['babel-loader']
}, {
test: /\.json?$/,
exclude: /node_modules/,
include: [CONTEXT],
loaders: ['json-loader']
}]
}
}; };

View File

@ -3360,7 +3360,7 @@ loader-runner@^2.2.0:
version "2.2.0" version "2.2.0"
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.2.0.tgz#824c1b699c4e7a2b6501b85902d5b862bf45b3fa" 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" version "0.2.16"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz#f08632066ed8282835dff88dfb52704765adee6d" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz#f08632066ed8282835dff88dfb52704765adee6d"
dependencies: dependencies:
@ -3605,6 +3605,10 @@ mime@^1.3.4, mime@~1.3.4, mime@1.3.4:
version "1.3.4" version "1.3.4"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53" 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: min-document@^2.19.0:
version "2.19.0" version "2.19.0"
resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685" 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" version "1.0.4"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91" 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" version "1.1.3"
resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-1.1.3.tgz#9f5b19cff1b53e9063fdf82ccdf024dfd4d68d21" resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-1.1.3.tgz#9f5b19cff1b53e9063fdf82ccdf024dfd4d68d21"
dependencies: dependencies:
@ -5333,6 +5337,13 @@ upper-case@^1.1.1:
version "1.1.3" version "1.1.3"
resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-1.1.3.tgz#f6b4501c2ec4cdd26ba78be7222961de77621598" 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: url-parse-lax@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/url-parse-lax/-/url-parse-lax-1.0.0.tgz#7af8f303645e9bd79a272e7a14ac68bc0609da73" resolved "https://registry.yarnpkg.com/url-parse-lax/-/url-parse-lax-1.0.0.tgz#7af8f303645e9bd79a272e7a14ac68bc0609da73"