Skip to content

Commit

Permalink
调整webpack配置文件命名
Browse files Browse the repository at this point in the history
  • Loading branch information
moocss committed Apr 16, 2017
1 parent 4a0bf76 commit 988beea
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 71 deletions.
27 changes: 12 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,40 @@
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# WebStorm
.idea

# OS or Editor folders
._*
.cache
.DS_Store

.vscode
.idea
.project
.settings
.tmproj
*.esproj
*.sublime-project
*.sublime-workspace
nbproject
Thumbs.db
6 changes: 3 additions & 3 deletions lib/cli/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ var _applyWebpackConfig = require('./../utils/applyWebpackConfig');

var _applyWebpackConfig2 = _interopRequireDefault(_applyWebpackConfig);

var _webpackProd = require('./../config/webpack.prod.config');
var _webpackConfig = require('./../config/webpack.config.prod');

var _webpackProd2 = _interopRequireDefault(_webpackProd);
var _webpackConfig2 = _interopRequireDefault(_webpackConfig);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

Expand Down Expand Up @@ -95,7 +95,7 @@ function build(argv) {
outputPath = argv.outputPath || rcConfig.outputPath || 'dist';
appBuild = paths.resolveApp(outputPath);

webPackProdConfig = (0, _webpackProd2.default)(argv, appBuild, rcConfig, paths);
webPackProdConfig = (0, _webpackConfig2.default)(argv, appBuild, rcConfig, paths);
config = (0, _applyWebpackConfig2.default)(webPackProdConfig, process.env.NODE_ENV);

return new Promise(function (resolve) {
Expand Down
6 changes: 3 additions & 3 deletions lib/cli/createServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ var _applyWebpackConfig = require('./../utils/applyWebpackConfig');

var _applyWebpackConfig2 = _interopRequireDefault(_applyWebpackConfig);

var _webpackDev = require('./../config/webpack.dev.config');
var _webpackConfig = require('./../config/webpack.config.dev');

var _webpackDev2 = _interopRequireDefault(_webpackDev);
var _webpackConfig2 = _interopRequireDefault(_webpackConfig);

var _mock = require('./../utils/mock');

Expand Down Expand Up @@ -99,7 +99,7 @@ function readRcConfig() {
}

function readWebpackConfig() {
var webpackDevConfig = (0, _webpackDev2.default)(rcConfig, cwd);
var webpackDevConfig = (0, _webpackConfig2.default)(rcConfig, cwd);
config = (0, _applyWebpackConfig2.default)(webpackDevConfig, process.env.NODE_ENV);
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports.default = function (config, cwd) {
var publicPath = '/';
var paths = (0, _paths2.default)(cwd);
var styleLoaders = _getCSSLoaders2.default.styleLoaders({ sourceMap: config.cssSourceMap });
var commonConfig = (0, _webpackBase2.default)(config, paths);
var commonConfig = (0, _webpackConfig2.default)(config, paths);

return (0, _webpackMerge2.default)(commonConfig, {
devtool: 'cheap-module-source-map',
Expand Down Expand Up @@ -76,9 +76,9 @@ var _copyWebpackPlugin = require('copy-webpack-plugin');

var _copyWebpackPlugin2 = _interopRequireDefault(_copyWebpackPlugin);

var _webpackBase = require('./webpack.base.config');
var _webpackConfig = require('./webpack.config.base');

var _webpackBase2 = _interopRequireDefault(_webpackBase);
var _webpackConfig2 = _interopRequireDefault(_webpackConfig);

var _paths = require('./paths');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports.default = function (args, appBuild, config, paths) {
extract: true
});

var commonConfig = (0, _webpackBase2.default)(config, paths);
var commonConfig = (0, _webpackConfig2.default)(config, paths);

return (0, _webpackMerge2.default)(commonConfig, {
bail: true,
Expand Down Expand Up @@ -109,9 +109,9 @@ var _getEntry = require('../utils/getEntry');

var _getEntry2 = _interopRequireDefault(_getEntry);

var _webpackBase = require('./webpack.base.config');
var _webpackConfig = require('./webpack.config.base');

var _webpackBase2 = _interopRequireDefault(_webpackBase);
var _webpackConfig2 = _interopRequireDefault(_webpackConfig);

var _getCSSLoaders = require('./../utils/getCSSLoaders');

Expand Down
70 changes: 31 additions & 39 deletions lib/utils/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,20 @@ var paths = (0, _paths2.default)(process.cwd());
function getConfig(filePath) {
var resolvedFilePath = paths.resolveApp(filePath);
if (_fs2.default.existsSync(resolvedFilePath)) {
var _ret = function () {
var files = [];
var realRequire = require.extensions['.js'];
require.extensions['.js'] = function (m, filename) {
if (filename.indexOf(paths.appNodeModules) === -1) {
files.push(filename);
}
delete require.cache[filename];
return realRequire(m, filename);
};

var config = require(resolvedFilePath); // eslint-disable-line
require.extensions['.js'] = realRequire;

return {
v: { config: config, files: files }
};
}();

if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
var files = [];
var realRequire = require.extensions['.js'];
require.extensions['.js'] = function (m, filename) {
if (filename.indexOf(paths.appNodeModules) === -1) {
files.push(filename);
}
delete require.cache[filename];
return realRequire(m, filename);
};

var config = require(resolvedFilePath); // eslint-disable-line
require.extensions['.js'] = realRequire;

return { config: config, files: files };
}
}

Expand All @@ -79,25 +73,23 @@ function applyMock(devServer) {
realApplyMock(devServer);
error = null;
} catch (e) {
(function () {
// 避免 require mock 文件出错时 100% cpu
require.extensions['.js'] = realRequire;

error = e;

console.log();
outputError();

var watcher = _chokidar2.default.watch(paths.resolveApp(CONFIG_FILE), {
ignored: /node_modules/,
persistent: true
});
watcher.on('change', function (path) {
console.log(_chalk2.default.green('CHANGED'), path.replace(paths.appDirectory, '.'));
watcher.close();
applyMock(devServer);
});
})();
// 避免 require mock 文件出错时 100% cpu
require.extensions['.js'] = realRequire;

error = e;

console.log();
outputError();

var watcher = _chokidar2.default.watch(paths.resolveApp(CONFIG_FILE), {
ignored: /node_modules/,
persistent: true
});
watcher.on('change', function (path) {
console.log(_chalk2.default.green('CHANGED'), path.replace(paths.appDirectory, '.'));
watcher.close();
applyMock(devServer);
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bees-cli",
"version": "0.5.11",
"version": "0.5.12",
"description": "A simple CLI for serve and build web app, support JSON pattern config.",
"bin": {
"bee": "./bin/bee"
Expand Down
2 changes: 1 addition & 1 deletion src/cli/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import stripAnsi from 'strip-ansi'
import getPaths from './../config/paths'
import getConfig from './../utils/getConfig'
import applyWebpackConfig, { warnIfExists } from './../utils/applyWebpackConfig'
import WebPackProdConfig from './../config/webpack.prod.config'
import WebPackProdConfig from './../config/webpack.config.prod'

process.env.NODE_ENV = 'production'

Expand Down
2 changes: 1 addition & 1 deletion src/cli/createServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import chokidar from 'chokidar'
import getPaths from './../config/paths'
import getConfig from './../utils/getConfig'
import applyWebpackConfig, { warnIfExists } from './../utils/applyWebpackConfig'
import WebpackDevConfig from './../config/webpack.dev.config'
import WebpackDevConfig from './../config/webpack.config.dev'
import { applyMock, outputError as outputMockError } from './../utils/mock'

process.env.NODE_ENV = 'development'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FriendlyErrors from 'friendly-errors-webpack-plugin'
import webpack from 'webpack'
import merge from 'webpack-merge'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import baseWebpackConfig from './webpack.base.config'
import baseWebpackConfig from './webpack.config.base'
import getPaths from './paths'
import getEntry from '../utils/getEntry'
import getCSSLoaders from './../utils/getCSSLoaders'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UglifyJsParallelPlugin from 'webpack-uglify-parallel'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import getEntry from '../utils/getEntry'
import baseWebpackConfig from './webpack.base.config'
import baseWebpackConfig from './webpack.config.base'
import getCSSLoaders from './../utils/getCSSLoaders'
import normalizeDefine from './../utils/normalizeDefine'

Expand Down

0 comments on commit 988beea

Please sign in to comment.