|
| 1 | +const path = require('path') |
| 2 | + , deepAssign = require('deep-assign') |
| 3 | + , rootPath = path.resolve(__dirname) |
| 4 | + , srcPath = path.resolve(rootPath, 'src') |
| 5 | + , pkg = require('./package.json') |
| 6 | + , libraryName = (function (str) { |
| 7 | + return str.split("-").map(function (c, i) { |
| 8 | + return i > 0 ? (c.charAt(0).toUpperCase() + c.substring(1)) : c; |
| 9 | + }).join(''); |
| 10 | +})(pkg.name) |
| 11 | + , webpack = require('atool-build/lib/webpack'); |
| 12 | + |
| 13 | +module.exports = function (webpackConfig) { |
| 14 | + webpackConfig.entry = { |
| 15 | + [`${pkg.name}.min`]: path.resolve(srcPath, 'index.js') |
| 16 | + } |
| 17 | + webpackConfig.externals = { |
| 18 | + [`react`]: { |
| 19 | + root: 'React', |
| 20 | + commonjs2: 'react', |
| 21 | + commonjs: 'react', |
| 22 | + amd: 'react', |
| 23 | + }, |
| 24 | + [`dplayer`]: "DPlayer", |
| 25 | + [`dplayer/dist/DPlayer.min.css`]: "null", |
| 26 | + }; |
| 27 | + |
| 28 | + /** |
| 29 | + * remove commonjs |
| 30 | + */ |
| 31 | + webpackConfig.plugins = webpackConfig.plugins.filter((plugin) => { |
| 32 | + const ret = !(plugin instanceof webpack.optimize.CommonsChunkPlugin); |
| 33 | + return ret; |
| 34 | + }); |
| 35 | + webpackConfig.output.library = libraryName; |
| 36 | + webpackConfig.output.libraryTarget = 'umd'; |
| 37 | + webpackConfig.plugins.push(new webpack.BannerPlugin( |
| 38 | + `${ pkg.name} v${pkg.version} |
| 39 | +
|
| 40 | +Copyright 2017-present, MoePlayer, Inc. |
| 41 | +All rights reserved.` |
| 42 | + )); |
| 43 | + let uncompressedWebpackConfig = deepAssign({}, webpackConfig); |
| 44 | + uncompressedWebpackConfig.entry = { |
| 45 | + [`${pkg.name}`]: path.resolve(srcPath, 'index.js') |
| 46 | + } |
| 47 | + uncompressedWebpackConfig.plugins = webpackConfig.plugins.filter((plugin) => { |
| 48 | + const ret = !(plugin instanceof webpack.optimize.UglifyJsPlugin); |
| 49 | + return ret; |
| 50 | + }); |
| 51 | + uncompressedWebpackConfig.plugins = uncompressedWebpackConfig.plugins.filter((plugin) => { |
| 52 | + const ret = !(plugin instanceof webpack.DefinePlugin); |
| 53 | + return ret; |
| 54 | + }); |
| 55 | + uncompressedWebpackConfig.plugins.push(new webpack.DefinePlugin({ |
| 56 | + 'process.env.NODE_ENV': JSON.stringify('development'), |
| 57 | + })); |
| 58 | + |
| 59 | + return [webpackConfig, uncompressedWebpackConfig]; |
| 60 | +} |
0 commit comments