1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-01 07:30:07 +02:00
copilot/packages/cp-frontend/scripts/webpack.config.dev.js
Sérgio Ramos 8295bd6882 chore: initial lerna setup
this shall be a progressive process
2017-05-25 10:56:50 +01:00

65 lines
1.6 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const paths = require('./paths');
const originalConfig = require('./webpack.config.dev.original');
const FRONTEND_ROOT = process.cwd();
const FRONTEND = path.join(FRONTEND_ROOT, 'src');
const STATIC = path.join(FRONTEND_ROOT, 'static');
const ESLINT = path.join(FRONTEND_ROOT, '.eslintrc');
const rules = originalConfig.module.rules.reduce((loaders, loader, index) => {
if (index === 3) {
loaders.push({
test: loader.test,
include: loader.include,
loader: loader.loader,
options: {
babelrc: true,
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 }));
} else {
loaders.push(loader);
}
return loaders;
}, []);
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
}
)
);
originalConfig.module.rules = rules;
originalConfig.resolve.alias = aliases;
originalConfig.resolve.plugins = [];
module.exports = originalConfig;