Reuse Webpack Configs
This commit is contained in:
225
js/webpack/config.js
Normal file
225
js/webpack/config.js
Normal file
@@ -0,0 +1,225 @@
|
||||
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
const path = require('path');
|
||||
const postcssImport = require('postcss-import');
|
||||
const postcssNested = require('postcss-nested');
|
||||
const postcssVars = require('postcss-simple-vars');
|
||||
const rucksack = require('rucksack-css');
|
||||
const webpack = require('webpack');
|
||||
const WebpackErrorNotificationPlugin = require('webpack-error-notification');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
const Shared = require('./shared');
|
||||
|
||||
const ENV = process.env.NODE_ENV || 'development';
|
||||
const isProd = ENV === 'production';
|
||||
const DEST = process.env.BUILD_DEST || '.build';
|
||||
|
||||
const FAVICON = path.resolve(__dirname, '../assets/images/parity-logo-black-no-text.png');
|
||||
|
||||
const DAPPS = [
|
||||
{ name: 'basiccoin', entry: './dapps/basiccoin.js', title: 'Basic Token Deployment' },
|
||||
{ name: 'dappreg', entry: './dapps/dappreg.js', title: 'Dapp Registry' },
|
||||
{ name: 'githubhint', entry: './dapps/githubhint.js', title: 'GitHub Hint', secure: true },
|
||||
{ name: 'localtx', entry: './dapps/localtx.js', title: 'Local transactions Viewer', secure: true },
|
||||
{ name: 'registry', entry: './dapps/registry.js', title: 'Registry' },
|
||||
{ name: 'signaturereg', entry: './dapps/signaturereg.js', title: 'Method Signature Registry' },
|
||||
{ name: 'tokenreg', entry: './dapps/tokenreg.js', title: 'Token Registry' }
|
||||
];
|
||||
|
||||
// dapps
|
||||
const entry = DAPPS.reduce((_entry, dapp) => {
|
||||
_entry[dapp.name] = dapp.entry;
|
||||
return _entry;
|
||||
}, {});
|
||||
|
||||
// main UI
|
||||
entry.index = './index.js';
|
||||
|
||||
module.exports = {
|
||||
debug: !isProd,
|
||||
cache: !isProd,
|
||||
devtool: isProd ? '#eval' : '#cheap-module-eval-source-map',
|
||||
context: path.join(__dirname, '../src'),
|
||||
entry: entry,
|
||||
output: {
|
||||
path: path.join(__dirname, '../', DEST),
|
||||
filename: '[name].[hash].js'
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: [ /node_modules/, /vendor\.js$/ ],
|
||||
loaders: [ 'happypack/loader?id=js' ]
|
||||
},
|
||||
{
|
||||
test: /vendor\.js$/,
|
||||
loaders: [ 'file?name=[name].[hash].[ext]' ]
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
include: /node_modules\/material-ui-chip-input/,
|
||||
loader: 'babel'
|
||||
},
|
||||
{
|
||||
test: /\.json$/,
|
||||
loaders: ['json']
|
||||
},
|
||||
{
|
||||
test: /\.html$/,
|
||||
loader: 'file?name=[name].[ext]!extract-loader!html-loader'
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.css$/,
|
||||
include: [/src/],
|
||||
loaders: [ 'happypack/loader?id=css' ]
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
exclude: [/src/],
|
||||
loader: 'style!css'
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg)$/,
|
||||
loader: 'file-loader?name=[name].[hash].[ext]'
|
||||
},
|
||||
{
|
||||
test: /\.(woff(2)|ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
||||
loader: 'file-loader'
|
||||
}
|
||||
],
|
||||
noParse: [
|
||||
/node_modules\/sinon/
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
root: path.join(__dirname, '../node_modules'),
|
||||
fallback: path.join(__dirname, '../node_modules'),
|
||||
extensions: ['', '.js', '.jsx'],
|
||||
unsafeCache: true
|
||||
},
|
||||
resolveLoaders: {
|
||||
root: path.join(__dirname, '../node_modules'),
|
||||
fallback: path.join(__dirname, '../node_modules')
|
||||
},
|
||||
|
||||
htmlLoader: {
|
||||
root: path.resolve(__dirname, '../assets/images'),
|
||||
attrs: ['img:src', 'link:href']
|
||||
},
|
||||
|
||||
postcss: [
|
||||
postcssImport({
|
||||
addDependencyTo: webpack
|
||||
}),
|
||||
postcssNested({}),
|
||||
postcssVars({
|
||||
unknown: function (node, name, result) {
|
||||
node.warn(result, `Unknown variable ${name}`);
|
||||
}
|
||||
}),
|
||||
rucksack({
|
||||
autoprefixer: true
|
||||
})
|
||||
],
|
||||
plugins: (function () {
|
||||
const plugins = Shared.getPlugins().concat([
|
||||
new CopyWebpackPlugin([{ from: './error_pages.css', to: 'styles.css' }], {}),
|
||||
new WebpackErrorNotificationPlugin(),
|
||||
|
||||
new webpack.DllReferencePlugin({
|
||||
context: '.',
|
||||
manifest: require(`../${DEST}/vendor-manifest.json`)
|
||||
}),
|
||||
|
||||
new HtmlWebpackPlugin({
|
||||
title: 'Parity',
|
||||
filename: 'index.html',
|
||||
template: './index.ejs',
|
||||
favicon: FAVICON,
|
||||
chunks: [ isProd ? null : 'commons', 'index' ]
|
||||
})
|
||||
], DAPPS.map((dapp) => {
|
||||
return new HtmlWebpackPlugin({
|
||||
title: dapp.title,
|
||||
filename: dapp.name + '.html',
|
||||
template: './dapps/index.ejs',
|
||||
favicon: FAVICON,
|
||||
secure: dapp.secure,
|
||||
chunks: [ isProd ? null : 'commons', dapp.name ]
|
||||
});
|
||||
}));
|
||||
|
||||
if (!isProd) {
|
||||
plugins.push(
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
filename: 'commons.js',
|
||||
name: 'commons'
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return plugins;
|
||||
}()),
|
||||
devServer: {
|
||||
contentBase: path.resolve(__dirname, `../${DEST}`),
|
||||
historyApiFallback: false,
|
||||
quiet: false,
|
||||
hot: !isProd,
|
||||
proxy: [
|
||||
{
|
||||
context: (pathname, req) => {
|
||||
return pathname === '/' && req.method === 'HEAD';
|
||||
},
|
||||
target: 'http://127.0.0.1:8180',
|
||||
changeOrigin: true,
|
||||
autoRewrite: true
|
||||
},
|
||||
{
|
||||
context: '/api',
|
||||
target: 'http://127.0.0.1:8080',
|
||||
changeOrigin: true,
|
||||
autoRewrite: true
|
||||
},
|
||||
{
|
||||
context: '/app',
|
||||
target: 'http://127.0.0.1:8080',
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^/app': ''
|
||||
}
|
||||
},
|
||||
{
|
||||
context: '/parity-utils',
|
||||
target: 'http://127.0.0.1:3000',
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^/parity-utils': ''
|
||||
}
|
||||
},
|
||||
{
|
||||
context: '/rpc',
|
||||
target: 'http://127.0.0.1:8080',
|
||||
changeOrigin: true
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
57
js/webpack/libraries.js
Normal file
57
js/webpack/libraries.js
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Run with `webpack --config webpack.libraries.js --progress`
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const Shared = require('./shared');
|
||||
|
||||
const DEST = process.env.BUILD_DEST || '.build';
|
||||
|
||||
module.exports = {
|
||||
context: path.join(__dirname, '../src'),
|
||||
entry: {
|
||||
// library
|
||||
'inject': ['./web3.js'],
|
||||
'web3': ['./web3.js'],
|
||||
'parity': ['./parity.js']
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, '../', DEST),
|
||||
filename: '[name].js',
|
||||
library: '[name].js',
|
||||
libraryTarget: 'umd'
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'happypack/loader?id=js'
|
||||
},
|
||||
{
|
||||
test: /\.json$/,
|
||||
loaders: ['json']
|
||||
},
|
||||
{
|
||||
test: /\.html$/,
|
||||
loader: 'file?name=[name].[ext]'
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: Shared.getPlugins()
|
||||
};
|
||||
78
js/webpack/npm.js
Normal file
78
js/webpack/npm.js
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const packageJson = require('../package.json');
|
||||
|
||||
const Shared = require('./shared');
|
||||
|
||||
const ENV = process.env.NODE_ENV || 'development';
|
||||
const isProd = ENV === 'production';
|
||||
|
||||
module.exports = {
|
||||
context: path.join(__dirname, '../src'),
|
||||
target: 'node',
|
||||
entry: 'library.js',
|
||||
output: {
|
||||
path: path.join(__dirname, '../.npmjs'),
|
||||
filename: 'library.js',
|
||||
library: 'Parity',
|
||||
libraryTarget: 'umd',
|
||||
umdNamedDefine: true
|
||||
},
|
||||
externals: {
|
||||
'node-fetch': 'node-fetch',
|
||||
'vertx': 'vertx'
|
||||
},
|
||||
module: {
|
||||
noParse: [
|
||||
/babel-polyfill/
|
||||
],
|
||||
loaders: [
|
||||
{
|
||||
test: /(\.jsx|\.js)$/,
|
||||
loaders: [ 'happypack/loader?id=js' ],
|
||||
exclude: /node_modules/
|
||||
}
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
root: path.resolve('./src'),
|
||||
extensions: ['', '.js']
|
||||
},
|
||||
plugins: Shared.getPlugins().concat([
|
||||
new CopyWebpackPlugin([
|
||||
{
|
||||
from: '../parity.package.json',
|
||||
to: 'package.json',
|
||||
transform: function (content, path) {
|
||||
const json = JSON.parse(content.toString());
|
||||
json.version = packageJson.version;
|
||||
return new Buffer(JSON.stringify(json, null, ' '), 'utf-8');
|
||||
}
|
||||
},
|
||||
{
|
||||
from: '../LICENSE'
|
||||
},
|
||||
{
|
||||
from: '../parity.md',
|
||||
to: 'README.md'
|
||||
}
|
||||
], { copyUnmodified: true })
|
||||
])
|
||||
};
|
||||
73
js/webpack/shared.js
Normal file
73
js/webpack/shared.js
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
const webpack = require('webpack');
|
||||
const HappyPack = require('happypack');
|
||||
|
||||
const ENV = process.env.NODE_ENV || 'development';
|
||||
const isProd = ENV === 'production';
|
||||
|
||||
function getPlugins (_isProd = isProd) {
|
||||
const plugins = [
|
||||
new HappyPack({
|
||||
id: 'css',
|
||||
threads: 4,
|
||||
loaders: [
|
||||
'style',
|
||||
'css?modules&sourceMap&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
|
||||
'postcss'
|
||||
]
|
||||
}),
|
||||
|
||||
new HappyPack({
|
||||
id: 'js',
|
||||
threads: 4,
|
||||
loaders: _isProd ? ['babel'] : [
|
||||
'react-hot',
|
||||
'babel?cacheDirectory=true'
|
||||
]
|
||||
}),
|
||||
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: JSON.stringify(ENV),
|
||||
RPC_ADDRESS: JSON.stringify(process.env.RPC_ADDRESS),
|
||||
PARITY_URL: JSON.stringify(process.env.PARITY_URL),
|
||||
LOGGING: JSON.stringify(!isProd)
|
||||
}
|
||||
})
|
||||
];
|
||||
|
||||
if (_isProd) {
|
||||
plugins.push(new webpack.optimize.OccurrenceOrderPlugin(false));
|
||||
plugins.push(new webpack.optimize.DedupePlugin());
|
||||
plugins.push(new webpack.optimize.UglifyJsPlugin({
|
||||
screwIe8: true,
|
||||
compress: {
|
||||
warnings: false
|
||||
},
|
||||
output: {
|
||||
comments: false
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPlugins: getPlugins
|
||||
};
|
||||
83
js/webpack/vendor.js
Normal file
83
js/webpack/vendor.js
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
const webpack = require('webpack');
|
||||
const path = require('path');
|
||||
|
||||
const Shared = require('./shared');
|
||||
|
||||
const ENV = process.env.NODE_ENV || 'development';
|
||||
const DEST = process.env.BUILD_DEST || '.build';
|
||||
|
||||
let modules = [
|
||||
'babel-polyfill',
|
||||
'bignumber.js',
|
||||
'blockies',
|
||||
'brace',
|
||||
'browserify-aes',
|
||||
'chart.js',
|
||||
'ethereumjs-tx',
|
||||
'lodash',
|
||||
'material-ui',
|
||||
'mobx',
|
||||
'mobx-react',
|
||||
'moment',
|
||||
'react',
|
||||
'react-dom',
|
||||
'react-redux',
|
||||
'react-router',
|
||||
'react-router-redux',
|
||||
'recharts',
|
||||
'redux',
|
||||
'redux-thunk',
|
||||
'scryptsy'
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
entry: {
|
||||
vendor: modules
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{
|
||||
test: /\.json$/,
|
||||
loaders: ['json']
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
include: /(ethereumjs-tx)/,
|
||||
loaders: [ 'happypack/loader?id=js' ]
|
||||
}
|
||||
]
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
path: path.resolve(__dirname, '../', `${DEST}/`),
|
||||
library: '[name]_lib'
|
||||
},
|
||||
plugins: Shared.getPlugins().concat([
|
||||
new webpack.DllPlugin({
|
||||
name: '[name]_lib',
|
||||
path: path.resolve(__dirname, '../', `${DEST}/[name]-manifest.json`)
|
||||
}),
|
||||
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: JSON.stringify(ENV)
|
||||
}
|
||||
})
|
||||
])
|
||||
};
|
||||
Reference in New Issue
Block a user