Skip to content
This repository has been archived by the owner on Dec 12, 2017. It is now read-only.

Commit

Permalink
Merge pull request #1 from ElemeFE/feature/fix-webpack-plugins
Browse files Browse the repository at this point in the history
Feature/fix webpack plugins
  • Loading branch information
QingWei-Li committed Mar 14, 2016
2 parents 081c9a8 + 8936a8f commit 40f848c
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 27 deletions.
11 changes: 10 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ build mode, output assets to the `dist` directory.

# cooking.conf.js

Configure your webpack.
```javacript
module.exports = function(webpack) {
return {
use: 'vue',
port: '8080',
// Configure your webpack.
};
};
```

# Inspiration
[@egoist/tooling](https://github.com/egoist/tooling)
Expand Down
11 changes: 7 additions & 4 deletions bin/cooking-watch
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ var utils = require('./../src/utils');
var CONTACTS = require('./../src/contacts');

module.exports = function() {
var userConfig = utils.loadUserConfig();
var baseConfig, userConfig, compiler, port, config;

userConfig = utils.loadUserConfig(webpack);
if (!userConfig) {
return;
}
var config = utils.loadWebpackConfig(CONTACTS.DEV, userConfig.use);
var compiler = webpack(utils.webpackMerge(config, userConfig));
var port = userConfig.port || 8080;

baseConfig = utils.loadWebpackConfig(CONTACTS.DEV, userConfig.use);
config = utils.webpackMerge(baseConfig, userConfig);
compiler = webpack(config);
port = userConfig.port || 8080;
WebpackHotServer({
config: config,
port: port,
Expand Down
8 changes: 5 additions & 3 deletions example/angular/cooking.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
use: 'angular',
port: '8080'
module.exports = function(webpack) {
return {
use: 'angular',
port: '8080'
};
};
8 changes: 5 additions & 3 deletions example/react/cooking.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
use: 'react',
port: '8080'
module.exports = function(webpack) {
return {
use: 'react',
port: '8080'
};
};
8 changes: 5 additions & 3 deletions example/vue/cooking.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
use: 'vue',
port: '8080'
module.exports = function(webpack) {
return {
use: 'vue',
port: '8080'
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cooking",
"version": "0.1.2",
"version": "0.1.3",
"description": "The basic configuration webpack for your project.",
"bin": {
"cooking": "bin/cooking"
Expand Down
8 changes: 5 additions & 3 deletions src/configs/angular/cooking.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
use: 'angular',
port: '8080'
module.exports = function(webpack) {
return {
use: 'angular',
port: '8080'
};
};
8 changes: 5 additions & 3 deletions src/configs/react/cooking.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
use: 'react',
port: '8080'
module.exports = function(webpack) {
return {
use: 'react',
port: '8080'
};
};
8 changes: 5 additions & 3 deletions src/configs/vue/cooking.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
use: 'vue',
port: '8080'
module.exports = function(webpack) {
return {
use: 'vue',
port: '8080'
};
};
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ module.exports = {
return path.join(__dirname, '../' + filePath);
},

loadUserConfig: function() {
loadUserConfig: function(webpack) {
try {
return require(cwd('cooking.conf.js'));
return require(cwd('cooking.conf.js'))(webpack);
} catch(err) {
console.error('\ncooking.conf.js not exist. please run "cooking init".\n');
throw Error(err);
return;
}
},
Expand Down

0 comments on commit 40f848c

Please sign in to comment.