1 | 'use strict'
|
2 |
|
3 | const webpack = require('webpack')
|
4 | const merge = require('webpack-merge')
|
5 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
6 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
7 | const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
8 |
|
9 | const config = require('../config')
|
10 | const { banner, getEntries } = require('../libs/utils')
|
11 |
|
12 | const maraConf = require(config.paths.marauder)
|
13 | const shouldUseSourceMap = !!maraConf.sourceMap
|
14 |
|
15 | function getLibraryConf() {
|
16 | const pkgName = require(config.paths.packageJson).name
|
17 |
|
18 | return pkgName
|
19 | }
|
20 |
|
21 | module.exports = function(options) {
|
22 | const baseWebpackConfig = require('./webpack.base.conf')('__LIB__')
|
23 |
|
24 | const webpackConfig = merge(baseWebpackConfig, {
|
25 |
|
26 | bail: true,
|
27 | entry: getEntries(config.paths.libEntry),
|
28 | devtool: shouldUseSourceMap ? 'source-map' : false,
|
29 | output: {
|
30 | path: config.paths.lib,
|
31 | filename: options.filename,
|
32 | library: getLibraryConf(),
|
33 |
|
34 | libraryTarget: options.format
|
35 | },
|
36 | plugins: [
|
37 | new webpack.DefinePlugin(config.build.env.stringified),
|
38 | options.minify &&
|
39 | new UglifyJsPlugin({
|
40 | uglifyOptions: {
|
41 | ecma: 5,
|
42 | compress: {
|
43 | warnings: false,
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | comparisons: false
|
49 | },
|
50 | mangle: {
|
51 | safari10: true
|
52 | },
|
53 | output: {
|
54 | comments: false,
|
55 |
|
56 |
|
57 | ascii_only: true
|
58 | }
|
59 | },
|
60 |
|
61 |
|
62 | parallel: true,
|
63 |
|
64 | cache: true,
|
65 | sourceMap: shouldUseSourceMap
|
66 | }),
|
67 | new webpack.BannerPlugin({
|
68 | banner: banner(),
|
69 | entryOnly: true
|
70 | }),
|
71 | new ExtractTextPlugin({
|
72 | filename: options.minify ? 'style.min.css' : 'style.css'
|
73 | }),
|
74 | options.minify &&
|
75 | new OptimizeCssAssetsPlugin({
|
76 |
|
77 |
|
78 |
|
79 | cssProcessorOptions: Object.assign(
|
80 | { autoprefixer: false, safe: true },
|
81 | shouldUseSourceMap
|
82 | ? {
|
83 | map: { inline: false }
|
84 | }
|
85 | : {}
|
86 | ),
|
87 | canPrint: false
|
88 | }),
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
|
95 | ].filter(Boolean)
|
96 | })
|
97 |
|
98 | return webpackConfig
|
99 | }
|