Commit 17c0fb35 authored by 邓晓峰's avatar 邓晓峰

feat: add webpack outpath

parent ed789439
...@@ -10,6 +10,8 @@ var pkg = require('../../package.json'); ...@@ -10,6 +10,8 @@ var pkg = require('../../package.json');
var CopyPlugin = require('copy-webpack-plugin'); var CopyPlugin = require('copy-webpack-plugin');
var argv = require('../../server/argv');
var ASSET_PATH = process.env.ASSET_PATH || '/'; var ASSET_PATH = process.env.ASSET_PATH || '/';
module.exports = function (options) { module.exports = function (options) {
...@@ -17,7 +19,7 @@ module.exports = function (options) { ...@@ -17,7 +19,7 @@ module.exports = function (options) {
mode: options.mode, mode: options.mode,
entry: options.entry, entry: options.entry,
output: Object.assign({ output: Object.assign({
path: path.resolve(process.cwd(), pkg.name.toLocaleLowerCase()), path: path.resolve(argv.releasepath, pkg.name.toLocaleLowerCase()) || path.resolve(process.cwd(), pkg.name.toLocaleLowerCase()),
publicPath: "/".concat(pkg.name.toLocaleLowerCase()) publicPath: "/".concat(pkg.name.toLocaleLowerCase())
}, options.output), }, options.output),
// Merge with env dependent settings // Merge with env dependent settings
...@@ -146,7 +148,7 @@ module.exports = function (options) { ...@@ -146,7 +148,7 @@ module.exports = function (options) {
'process.env.ASSET_PATH': JSON.stringify(ASSET_PATH) 'process.env.ASSET_PATH': JSON.stringify(ASSET_PATH)
}), new CopyPlugin([{ }), new CopyPlugin([{
from: path.resolve(process.cwd(), 'theme'), from: path.resolve(process.cwd(), 'theme'),
to: path.resolve(process.cwd(), "".concat(pkg.name.toLocaleLowerCase(), "/theme")) to: path.resolve(argv.releasepath || process.cwd(), "".concat(pkg.name.toLocaleLowerCase(), "/theme"))
}])]), }])]),
resolve: { resolve: {
modules: ['node_modules', 'src'], modules: ['node_modules', 'src'],
......
...@@ -3,13 +3,14 @@ const webpack = require('webpack'); ...@@ -3,13 +3,14 @@ const webpack = require('webpack');
const slash = require('slash2'); const slash = require('slash2');
const pkg = require('../../package.json'); const pkg = require('../../package.json');
const CopyPlugin = require('copy-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin');
const argv = require('../../server/argv');
const ASSET_PATH = process.env.ASSET_PATH || '/'; const ASSET_PATH = process.env.ASSET_PATH || '/';
module.exports = options => ({ module.exports = options => ({
mode: options.mode, mode: options.mode,
entry: options.entry, entry: options.entry,
output: Object.assign( output: Object.assign(
{ {
path: path.resolve(process.cwd(), pkg.name.toLocaleLowerCase()), path: path.resolve(argv.releasepath, pkg.name.toLocaleLowerCase()) || path.resolve(process.cwd(), pkg.name.toLocaleLowerCase()),
publicPath: `/${pkg.name.toLocaleLowerCase()}`, publicPath: `/${pkg.name.toLocaleLowerCase()}`,
}, },
options.output, options.output,
...@@ -33,8 +34,7 @@ module.exports = options => ({ ...@@ -33,8 +34,7 @@ module.exports = options => ({
test: /\.css$/, test: /\.css$/,
exclude: /node_modules/, exclude: /node_modules/,
use: ['style-loader', 'css-loader'], use: ['style-loader', 'css-loader'],
}, }, {
{
test: /\.less$/, test: /\.less$/,
use: [ use: [
...@@ -165,12 +165,13 @@ module.exports = options => ({ ...@@ -165,12 +165,13 @@ module.exports = options => ({
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env.ASSET_PATH': JSON.stringify(ASSET_PATH), 'process.env.ASSET_PATH': JSON.stringify(ASSET_PATH),
}), }),
new CopyPlugin([ new CopyPlugin([
{ {
from: path.resolve(process.cwd(), 'theme'), from: path.resolve(process.cwd(), 'theme'),
to: path.resolve( to: path.resolve(
process.cwd(), argv.releasepath || process.cwd(),
`${pkg.name.toLocaleLowerCase()}/theme`, `${pkg.name.toLocaleLowerCase()}/theme`,
), ),
}, },
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"prebuild": "npm run build:clean", "prebuild": "npm run build:clean",
"build": "cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress --hide-modules --display-optimization-bailout", "build": "cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress --hide-modules --display-optimization-bailout",
"build:clean": "rimraf ./build", "build:clean": "rimraf ./build",
"start": "cross-env NODE_ENV=development node server", "start": "cross-env NODE_ENV=development node server --port=$port",
"start:tunnel": "cross-env NODE_ENV=development ENABLE_TUNNEL=true node server", "start:tunnel": "cross-env NODE_ENV=development ENABLE_TUNNEL=true node server",
"start:production": "npm run test && npm run build && npm run start:prod", "start:production": "npm run test && npm run build && npm run start:prod",
"start:prod": "cross-env NODE_ENV=production node server", "start:prod": "cross-env NODE_ENV=production node server",
......
"use strict";
/* eslint consistent-return:0 import/order:0 */
var express = require('express');
var logger = require('./logger');
var argv = require('./argv');
var port = require('./port');
var setup = require('./middlewares/frontendMiddleware');
var isDev = process.env.NODE_ENV !== 'production';
var pkg = require('../package.json');
var ngrok = isDev && process.env.ENABLE_TUNNEL || argv.tunnel ? require('ngrok') : false;
var _require = require('path'),
resolve = _require.resolve;
var app = express();
setup(app, {
outputPath: resolve(process.cwd(), pkg.name.toLocaleLowerCase()),
publicPath: "/".concat(pkg.name.toLocaleLowerCase())
});
var customHost = argv.host || process.env.HOST;
var host = customHost || null;
var prettyHost = customHost || 'localhost'; // use the gzipped bundle
app.get('*.js', function (req, res, next) {
req.url = req.url + '.gz'; // eslint-disable-line
res.set('Content-Encoding', 'gzip');
next();
}); // Start your app.
app.listen(port, host, function _callee(err) {
var url;
return regeneratorRuntime.async(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!err) {
_context.next = 2;
break;
}
return _context.abrupt("return", logger.error(err.message));
case 2:
if (!ngrok) {
_context.next = 15;
break;
}
_context.prev = 3;
_context.next = 6;
return regeneratorRuntime.awrap(ngrok.connect(port));
case 6:
url = _context.sent;
_context.next = 12;
break;
case 9:
_context.prev = 9;
_context.t0 = _context["catch"](3);
return _context.abrupt("return", logger.error(_context.t0));
case 12:
logger.appStarted(port, prettyHost, url);
_context.next = 16;
break;
case 15:
logger.appStarted(port, prettyHost);
case 16:
case "end":
return _context.stop();
}
}
}, null, null, [[3, 9]]);
});
\ No newline at end of file
"use strict";
var argv = require('./argv');
console.log(argv.port);
module.exports = parseInt(argv.port || process.env.PORT || '3005', 10);
\ No newline at end of file
...@@ -19,7 +19,6 @@ setup(app, { ...@@ -19,7 +19,6 @@ setup(app, {
outputPath: resolve(process.cwd(), pkg.name.toLocaleLowerCase()), outputPath: resolve(process.cwd(), pkg.name.toLocaleLowerCase()),
publicPath: `/${pkg.name.toLocaleLowerCase()}`, publicPath: `/${pkg.name.toLocaleLowerCase()}`,
}); });
const customHost = argv.host || process.env.HOST; const customHost = argv.host || process.env.HOST;
const host = customHost || null; const host = customHost || null;
const prettyHost = customHost || 'localhost'; const prettyHost = customHost || 'localhost';
......
const argv = require('./argv'); const argv = require('./argv');
console.log(argv.port)
module.exports = parseInt(argv.port || process.env.PORT || '3005', 10); module.exports = parseInt(argv.port || process.env.PORT || '3005', 10);
...@@ -482,7 +482,6 @@ const BasicLayout = props => { ...@@ -482,7 +482,6 @@ const BasicLayout = props => {
hideInMenu: false, hideInMenu: false,
routes: item.routes ? item.routes : undefined, routes: item.routes ? item.routes : undefined,
}; };
console.log("localItem", localItem)
return localItem return localItem
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment