build(my-joyent): use joyent-react-scripts
This commit is contained in:
parent
fd17bf995b
commit
fe3d5c1bb7
@ -5,15 +5,15 @@
|
||||
"repository": "github:yldio/joyent-portal",
|
||||
"main": "build/",
|
||||
"scripts": {
|
||||
"dev": "REACT_APP_GQL_PORT=4000 PORT=3069 REACT_APP_GQL_PROTOCOL=http react-scripts start",
|
||||
"start": "PORT=3069 react-scripts start",
|
||||
"build": "NODE_ENV=production react-scripts build",
|
||||
"dev":
|
||||
"REACT_APP_GQL_PORT=4000 PORT=3069 REACT_APP_GQL_PROTOCOL=http joyent-react-scripts start",
|
||||
"start": "PORT=3069 joyent-react-scripts start",
|
||||
"build": "NODE_ENV=production joyent-react-scripts build",
|
||||
"lint:css": "echo 0 `# stylelint './src/**/*.js'`",
|
||||
"lint:js": "eslint . --fix",
|
||||
"lint": "redrun -s lint:*",
|
||||
"test": "NODE_ENV=test ./test/run --env=jsdom",
|
||||
"test-ci": "echo 0 `# NODE_ENV=test ./test/run --env=jsdom --coverage`",
|
||||
"prepublish": "node scripts/postinstall"
|
||||
"test-ci": "echo 0 `# NODE_ENV=test ./test/run --env=jsdom --coverage`"
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo": "^0.2.2",
|
||||
@ -57,6 +57,7 @@
|
||||
"jest-snapshot": "^21.2.1",
|
||||
"jest-styled-components": "^4.7.0",
|
||||
"jest-transform-graphql": "^2.1.0",
|
||||
"joyent-react-scripts": "^2.3.0",
|
||||
"lodash.sortby": "^4.7.0",
|
||||
"mz": "^2.7.0",
|
||||
"react-scripts": "^1.0.14",
|
||||
|
@ -1,124 +0,0 @@
|
||||
const MinifyPlugin = require('babel-minify-webpack-plugin');
|
||||
const webpack = require('webpack');
|
||||
const isString = require('lodash.isstring');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const FRONTEND_ROOT = process.cwd();
|
||||
const FRONTEND = path.join(FRONTEND_ROOT, 'src');
|
||||
|
||||
const BabelLoader = loader => ({
|
||||
test: loader.test,
|
||||
include: loader.include,
|
||||
loader: loader.loader,
|
||||
options: {
|
||||
babelrc: true,
|
||||
compact: true
|
||||
}
|
||||
});
|
||||
|
||||
const FileLoader = loader => ({
|
||||
exclude: loader.exclude.concat([/\.(graphql|gql)$/]),
|
||||
loader: loader.loader,
|
||||
options: loader.options
|
||||
});
|
||||
|
||||
module.exports = config => {
|
||||
config.resolve.plugins = [];
|
||||
|
||||
config.plugins = config.plugins.map(
|
||||
plugin =>
|
||||
plugin instanceof webpack.optimize.UglifyJsPlugin
|
||||
? new MinifyPlugin()
|
||||
: plugin
|
||||
);
|
||||
|
||||
config.module.rules = config.module.rules
|
||||
.reduce((loaders, loader, index) => {
|
||||
if (Array.isArray(loader.use)) {
|
||||
return loaders.concat([
|
||||
Object.assign(loader, {
|
||||
use: loader.use.map(l => {
|
||||
if (isString(l) || !isString(l.loader)) {
|
||||
return l;
|
||||
}
|
||||
|
||||
if (!l.loader.match(/eslint-loader/)) {
|
||||
return l;
|
||||
}
|
||||
|
||||
return Object.assign(l, {
|
||||
options: Object.assign(l.options, {
|
||||
baseConfig: null,
|
||||
useEslintrc: true
|
||||
})
|
||||
});
|
||||
})
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
if (Array.isArray(loader.oneOf)) {
|
||||
return loaders.concat([
|
||||
Object.assign(loader, {
|
||||
oneOf: loader.oneOf.map(loader => {
|
||||
if (!isString(loader.loader)) {
|
||||
return loader;
|
||||
}
|
||||
|
||||
if (loader.loader.match(/babel-loader/)) {
|
||||
return BabelLoader(loader);
|
||||
}
|
||||
|
||||
if (loader.loader.match(/file-loader/)) {
|
||||
return FileLoader(loader);
|
||||
}
|
||||
|
||||
return loader;
|
||||
})
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
if (!isString(loader.loader)) {
|
||||
return loaders.concat([loader]);
|
||||
}
|
||||
|
||||
if (loader.loader.match(/babel-loader/)) {
|
||||
return loaders.concat(BabelLoader(loader));
|
||||
}
|
||||
|
||||
if (loader.loader.match(/file-loader/)) {
|
||||
return loaders.concat([FileLoader(loader)]);
|
||||
}
|
||||
|
||||
return loaders.concat([loader]);
|
||||
}, [])
|
||||
.concat([
|
||||
{
|
||||
test: /\.(graphql|gql)$/,
|
||||
exclude: /node_modules/,
|
||||
loader: require.resolve('graphql-tag/loader')
|
||||
}
|
||||
]);
|
||||
|
||||
config.resolve.alias = Object.assign(
|
||||
{},
|
||||
config.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
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
return config;
|
||||
};
|
@ -1,41 +0,0 @@
|
||||
const { readFile, writeFile, exists } = require('mz/fs');
|
||||
const main = require('apr-main');
|
||||
const forEach = require('apr-for-each');
|
||||
const path = require('path');
|
||||
|
||||
const ROOT = path.join(__dirname, '../../../node_modules/react-scripts/config');
|
||||
const configs = ['webpack.config.dev', 'webpack.config.prod'];
|
||||
|
||||
const toCopy = [
|
||||
'patch-webpack-config',
|
||||
'webpack.config.dev',
|
||||
'webpack.config.prod'
|
||||
];
|
||||
|
||||
const backup = async file => {
|
||||
const backupPath = path.join(ROOT, `${file}.original.js`);
|
||||
const backupExists = await exists(backupPath);
|
||||
|
||||
if (backupExists) {
|
||||
return;
|
||||
}
|
||||
|
||||
const originalPath = path.join(ROOT, `${file}.js`);
|
||||
const orignalConfig = await readFile(originalPath, 'utf-8');
|
||||
return writeFile(backupPath, orignalConfig);
|
||||
};
|
||||
|
||||
const copy = async file => {
|
||||
const srcPath = path.join(__dirname, `${file}.js`);
|
||||
const destPath = path.join(ROOT, `${file}.js`);
|
||||
|
||||
const src = await readFile(srcPath, 'utf-8');
|
||||
return writeFile(destPath, src);
|
||||
};
|
||||
|
||||
main(
|
||||
(async () => {
|
||||
await forEach(configs, backup);
|
||||
await forEach(toCopy, copy);
|
||||
})()
|
||||
);
|
@ -1,4 +0,0 @@
|
||||
const originalConfig = require('./webpack.config.dev.original');
|
||||
const patch = require('./patch-webpack-config');
|
||||
|
||||
module.exports = patch(originalConfig);
|
@ -1,4 +0,0 @@
|
||||
const originalConfig = require('./webpack.config.prod.original');
|
||||
const patch = require('./patch-webpack-config');
|
||||
|
||||
module.exports = patch(originalConfig);
|
Loading…
Reference in New Issue
Block a user