Skip to content

Commit

Permalink
feat: 增加配置项 plugins 和 postcssPlugins
Browse files Browse the repository at this point in the history
  • Loading branch information
booxood committed Jun 6, 2017
1 parent 20a525b commit c8e3f43
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module.exports = {
imgToBase64Dir: /src\/img-base64/,
externals: {},
rules: [],
plugins: [],
postcssPlugins: [],

/**
* webpack.CommonsChunkPlugin 默认配置
Expand Down
2 changes: 2 additions & 0 deletions config/default.out.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = {
imgToBase64Dir: /src\/img-base64/,
externals: {},
rules: [],
plugins: [],
postcssPlugins: [],

/**
* webpack.CommonsChunkPlugin 默认配置
Expand Down
10 changes: 5 additions & 5 deletions webpack/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ HeadJavascriptInjectPlugin.prototype.apply = function (compiler) {
})
}

var addOneOrMorePlugins = _.curry(function (pluginClass, plugins, options) {
const addOneOrMorePlugins = _.curry(function (pluginClass, plugins, options) {
if (_.isArray(options)) {
Array.prototype.push.apply(plugins, options.map(function (c) {
return new pluginClass(c)
Expand All @@ -111,12 +111,12 @@ var addOneOrMorePlugins = _.curry(function (pluginClass, plugins, options) {
return plugins
})

var addHtmlWebpackPlugins = addOneOrMorePlugins(HtmlWebpackPlugin)
const addHtmlWebpackPlugins = addOneOrMorePlugins(HtmlWebpackPlugin)

var addCommonChunkPlugins = addOneOrMorePlugins(webpack.optimize.CommonsChunkPlugin)
const addCommonChunkPlugins = addOneOrMorePlugins(webpack.optimize.CommonsChunkPlugin)

var getPlugins = function (config) {
var plugins = []
const getPlugins = function (config) {
var plugins = [].concat(config.plugins)

plugins.push(new webpack.DefinePlugin(config.definePluginOptions))
plugins.push(new HeadJavascriptInjectPlugin())
Expand Down
4 changes: 2 additions & 2 deletions webpack/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const allConfig = require('../config/index.js')
const NODE_ENV = process.env.NODE_ENV || ''
const config = _.merge({}, allConfig, allConfig[NODE_ENV.toUpperCase()])

let postcssPlugins = []
const postcssPlugins = [].concat(allConfig.postcssPlugins)

// assets
postcssPlugins.push(assets(config.assetsOptions))

// sprites
let spritesOptions = config.spritesOptions
const spritesOptions = config.spritesOptions
if (config.enableREM) {
const updateRule = require('postcss-sprites/lib/core').updateRule

Expand Down

0 comments on commit c8e3f43

Please sign in to comment.