Merge pull request #1 from status-im/webpack

feat: add webpack config for browser and node
This commit is contained in:
Iuri Matias 2019-08-09 15:15:37 -04:00 committed by GitHub
commit 2a14d55634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 3637 additions and 19 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ node_modules
.vscode
phoenix.db
TODO
test.js
test.js
dist

24
babel.config.js Normal file
View File

@ -0,0 +1,24 @@
/* global module */
module.exports = function (api) {
const node = {
ignore: [],
plugins: [],
presets: [
[
'@babel/preset-env', {
targets: {
node: '8.11.3'
}
}
]
]
};
switch (api.env()) {
case 'node':
return node;
default:
throw new Error(`invalid babel env: ${api.env}`);
}
};

View File

@ -2,10 +2,33 @@
"name": "phoenix",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"main": "./dist/node.js",
"browser": "./dist/browser.js",
"author": "",
"license": "MIT",
"scripts": {
"babel": "babel",
"babel:node": "npm-run-all babel:node:*",
"babel:node:src": "cross-env BABEL_ENV=node babel src --copy-files --extensions \".js\" --out-dir dist",
"webpack:dev": "webpack --config webpack.dev.js",
"build:dev": "npm-run-all babel:node webpack:dev",
"build": "npm-run-all build:dev",
"clean": "rimraf dist"
},
"devDependencies": {
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"babel-loader": "^8.0.4",
"babel-plugin-module-resolver": "^3.1.1",
"cross-env": "^5.2.0",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6",
"webpack-merge": "^4.2.1",
"webpack-node-externals": "^1.7.2",
"rimraf": "^2.6.2",
"npm-run-all": "^4.1.5"
},
"dependencies": {
"lokijs": "^1.5.6",
"rxjs": "^6.5.2",

8
test/index.html Normal file
View File

@ -0,0 +1,8 @@
<html>
<head>
<script type="text/javascript" src="../dist/browser.js"></script>
</head>
<body>
<h2>Test Page</h2>
</body>
</html>

29
webpack.common.js Normal file
View File

@ -0,0 +1,29 @@
const path = require('path');
const webConfig = {
target: 'web',
entry: path.join(__dirname, "src/index.js"),
output: {
path: path.resolve(__dirname, "dist"),
filename: 'browser.js',
library: 'phoenix',
libraryTarget: 'var'
},
node: {
fs: 'empty',
process: false
}
};
const nodeConfig = {
target: "node",
entry: path.join(__dirname, "src/index.js"),
output: {
path: path.resolve(__dirname, "dist"),
filename: "node.js",
library: 'phoenix',
libraryTarget: 'commonjs2',
}
};
module.exports = [nodeConfig, webConfig];

9
webpack.dev.js Normal file
View File

@ -0,0 +1,9 @@
const merge = require("webpack-merge");
const common = require("./webpack.common.js");
// TODO: use merge
common[0].mode = "development";
common[1].mode = "development";
module.exports = common;

3556
yarn.lock

File diff suppressed because it is too large Load Diff