Skip to content
This repository was archived by the owner on May 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions config/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
var path = require('path');
var fs = require('fs');
var url = require('url');

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
var appDirectory = fs.realpathSync(process.cwd());

function resolveApp(relativePath) {
return path.resolve(appDirectory, relativePath);
}

// We support resolving modules according to `NODE_PATH`.
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.

// It works similar to `NODE_PATH` in Node itself:
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders

// We will export `nodePaths` as an array of absolute paths.
// It will then be used by Webpack configs.
// Jest doesn’t need this because it already handles `NODE_PATH` out of the box.

// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421

var nodePaths = (process.env.NODE_PATH || '')
.split(process.platform === 'win32' ? ';' : ':')
.filter(Boolean)
.filter((folder) => !path.isAbsolute(folder))
.map(resolveApp);

var envPublicUrl = process.env.PUBLIC_URL;

function ensureSlash(path, needsSlash) {
var hasSlash = path.endsWith('/');

if (hasSlash && !needsSlash) {
return path.substr(path, path.length - 1);
} else if (!hasSlash && needsSlash) {
return path + '/';
} else {
return path;
}
}

function getPublicUrl(appPackageJson) {
return envPublicUrl || require(appPackageJson).homepage;
}

// We use `PUBLIC_URL` environment variable or "homepage" field to infer
// "public path" at which the app is served.
// Webpack needs to know it to put the right <script> hrefs into HTML even in
// single-page apps that may serve index.html for nested URLs like /todos/42.
// We can't use a relative path in HTML because we don't want to load something
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
function getServedPath(appPackageJson) {
var publicUrl = getPublicUrl(appPackageJson);
var servedUrl = envPublicUrl || (
publicUrl ? url.parse(publicUrl).pathname : '/'
);
return ensureSlash(servedUrl, true);
}

// config after eject: we're in ./config/
module.exports = {
appBuild: resolveApp('build'),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveApp('src/index.js'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
yarnLockFile: resolveApp('yarn.lock'),
testsSetup: resolveApp('src/setupTests.js'),
appNodeModules: resolveApp('node_modules'),
ownNodeModules: resolveApp('node_modules'),
nodePaths: nodePaths,
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json'))
};
17 changes: 3 additions & 14 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,14 @@ module.exports = function (options) {

// PROD OUTPUT PATH
outputPath = path.join(root_dir, 'build');

plugins.push(new CopyWebpackPlugin([{
from: path.resolve(root_dir, 'src/assets/openpgp'),
to: path.resolve(outputPath, 'openpgp')
},
{
from: path.resolve(root_dir, 'src/assets/createjs-2015.11.26.min.js'),
to: path.resolve(outputPath, 'createjs-2015.11.26.min.js')
},
]));
} else {

plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development')
}
})),

plugins.push(new webpack.HotModuleReplacementPlugin());

if (options.ugly) {
Expand Down Expand Up @@ -127,7 +119,7 @@ module.exports = function (options) {
devtool: options.prod ? 'cheap-module-source-map' : 'source-map',
debug: !options.prod,
module: {
noParse: /node_modules\/openpgp\/build\/openpgp.js/,
noParse: /node_modules\/build/,
loaders: [{
test: /\.jsx$/,
include: [
Expand Down Expand Up @@ -229,9 +221,6 @@ module.exports = function (options) {
remarkable: {
preset: 'full',
typographer: true
},
externals: {
'createjs': 'createjs'
}
};

Expand Down
234 changes: 229 additions & 5 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,229 @@
module.exports = require('./webpack.config')({
prod: true,
ugly: true,
electron: true
});
var path = require('path');
var paths = require('./paths');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var ManifestPlugin = require('webpack-manifest-plugin');
var Clean = require('clean-webpack-plugin');
require('es6-promise').polyfill();
var CopyWebpackPlugin = require('copy-webpack-plugin');
// BASE APP DIR
var root_dir = path.resolve(__dirname, '..');
var Config = require('./Config');

// Webpack uses `publicPath` to determine where the app is being served from.
// It requires a trailing slash, or the file assets will get an incorrect path.
var publicPath = paths.servedPath;

// FUNCTION TO EXTRACT CSS FOR PRODUCTION
function extractForProduction(loaders) {
return ExtractTextPlugin.extract('style', loaders.substr(loaders.indexOf('!')));
}

// STYLE LOADERS
var cssLoaders = 'style-loader!css-loader!postcss-loader',
scssLoaders = 'style!css!postcss-loader!sass?outputStyle=expanded';

// DIRECTORY CLEANER
var cleanDirectories = ['build'];

// OUTPUT PATH
var outputPath = path.join(root_dir, 'build');

// GLOBAL VAR DEFINE
var define = {
APP_PACKAGE_VERSION: JSON.stringify(Config.APP_PACKAGE_VERSION),
SOFTWARE_UPDATE_REFERENCE_ACCOUNT_NAME: JSON.stringify(
Config.SOFTWARE_UPDATE_REFERENCE_ACCOUNT_NAME
),
APP_VERSION: JSON.stringify(Config.APP_VERSION),
__ELECTRON__: true,
CORE_ASSET: JSON.stringify(Config.CORE_ASSET),
BLOCKCHAIN_URL: JSON.stringify(Config.BLOCKCHAIN_URLS),
FAUCET_URL: JSON.stringify(Config.FAUCET_URLS),
BITSHARES_WS: JSON.stringify(Config.BITSHARES_WS),
};

// COMMON PLUGINS
var plugins = [
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin(define),
new Clean(cleanDirectories, {
root: root_dir
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new ExtractTextPlugin('app.css'),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
sourceMap: true,
compress: {
warnings: false
},
output: {
screw_ie8: true
}
}),
new ManifestPlugin({
fileName: 'asset-manifest.json'
})
];

// WRAP INTO CSS FILE
cssLoaders = extractForProduction(cssLoaders);
scssLoaders = extractForProduction(scssLoaders);

// PROD OUTPUT PATH
outputPath = path.join(root_dir, 'build');

module.exports = {
bail: true,
devtool: 'source-map',
entry: {
app: path.resolve(root_dir, 'src/Main.js')
},
output: {
path: paths.appBuild,
filename: 'static/js/[name].[chunkhash:8].js',
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
publicPath: publicPath
},
debug: false,
module: {
noParse: /node_modules\/build/,
loaders: [{
test: /\.jsx$/,
include: [
path.join(root_dir, 'src'),
path.join(root_dir, 'node_modules/react-foundation-apps'),
'/home/sigve/Dev/graphene/react-foundation-apps'
],
loaders: ['babel-loader']
},
{
test: /\.js$/,
exclude: [/node_modules/, path.resolve(root_dir, '../node_modules')],
loader: 'babel-loader',
query: {
compact: false,
cacheDirectory: true
}
},
{
test: /\.json/,
loader: 'json',
exclude: [
path.resolve(root_dir, '../common'),
path.resolve(root_dir, 'src/assets/locales')
]
},
{
test: /\.coffee$/,
loader: 'coffee-loader'
},
{
test: /\.(coffee\.md|litcoffee)$/,
loader: 'coffee-loader?literate'
},
{
test: /\.css$/,
loader: cssLoaders
},
{
test: /\.scss$/,
loader: scssLoaders
},
{
test: /(\.png$)/,
loader: 'url-loader?limit=100000',
query: {
name: 'static/media/[name].[hash:8].[ext]'
},
exclude: [
path.resolve(root_dir, 'src/assets/asset-symbols'),
path.resolve(root_dir, 'src/assets/images')
]
},
{
test: /\.svg$/,
loader: 'file',
query: {
name: 'static/media/[name].[hash:8].[ext]'
}
},
{
test: /\.(jpe?g|png|gif)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
{
loader: 'image-webpack',
options: {
bypassOnDebug: true,
optipng: {
optimizationLevel: true
},
gifsicle: {
interlaced: true
}
}
}
],
exclude: [
path.join(root_dir, 'src/assets/images')
]
},
{
test: /\.woff$/,
loader: 'url-loader?limit=100000&mimetype=application/font-woff'
},
{
test: /.*\.svg$/,
loaders: ['svg-inline-loader', 'svgo-loader'],
exclude: [path.resolve(root_dir, 'src/assets/images/games/rps')]
},
{
test: /\.md/,
loader: 'html?removeAttributeQuotes=false!remarkable'
},
],
postcss: function () {
return [precss, autoprefixer];
}
},
resolve: {
root: [path.resolve(root_dir, './src')],
extensions: ['', '.js', '.jsx', '.coffee', '.json'],
modulesDirectories: ['node_modules'],
fallback: [path.resolve(root_dir, './node_modules')]
},
resolveLoader: {
root: path.join(root_dir, 'node_modules'),
fallback: [path.resolve(root_dir, './node_modules')]
},
plugins: plugins,
root: outputPath,
remarkable: {
preset: 'full',
typographer: true
}
};
6 changes: 0 additions & 6 deletions electron/.gitignore

This file was deleted.

Loading