Merge pull request #1 from status-im/webpack
feat: add webpack config for browser and node
This commit is contained in:
commit
2a14d55634
|
@ -3,3 +3,4 @@ node_modules
|
|||
phoenix.db
|
||||
TODO
|
||||
test.js
|
||||
dist
|
|
@ -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}`);
|
||||
}
|
||||
};
|
27
package.json
27
package.json
|
@ -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",
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="../dist/browser.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Test Page</h2>
|
||||
</body>
|
||||
</html>
|
|
@ -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];
|
|
@ -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;
|
Loading…
Reference in New Issue