|
1 |
| -var path = require('path') |
2 |
| -var config = require('../config') |
3 |
| -var utils = require('./utils') |
4 |
| -var webpack = require('webpack') |
5 |
| -var merge = require('webpack-merge') |
6 |
| -var baseWebpackConfig = require('./webpack.base.conf') |
7 |
| -var ExtractTextPlugin = require('extract-text-webpack-plugin') |
8 |
| -var HtmlWebpackPlugin = require('html-webpack-plugin') |
9 |
| -var env = process.env.NODE_ENV === 'testing' |
10 |
| - ? require('../config/test.env') |
11 |
| - : config.build.env |
| 1 | +const webpack = require('webpack') |
| 2 | +const base = require('./webpack.base.conf') |
| 3 | +const config = require('../config') |
12 | 4 |
|
13 |
| -var webpackConfig = merge(baseWebpackConfig, { |
14 |
| - module: { |
15 |
| - loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true }) |
16 |
| - }, |
17 |
| - devtool: config.build.productionSourceMap ? '#source-map' : false, |
18 |
| - output: { |
19 |
| - path: config.build.assetsRoot, |
20 |
| - filename: utils.assetsPath('js/[name].[chunkhash].js'), |
21 |
| - chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') |
22 |
| - }, |
23 |
| - vue: { |
24 |
| - loaders: utils.cssLoaders({ |
25 |
| - sourceMap: config.build.productionSourceMap, |
26 |
| - extract: true |
27 |
| - }) |
28 |
| - }, |
29 |
| - plugins: [ |
30 |
| - // http://vuejs.github.io/vue-loader/en/workflow/production.html |
31 |
| - new webpack.DefinePlugin({ |
32 |
| - 'process.env': env |
33 |
| - }), |
34 |
| - new webpack.optimize.UglifyJsPlugin({ |
35 |
| - compress: { |
36 |
| - warnings: false |
37 |
| - } |
38 |
| - }), |
39 |
| - new webpack.optimize.OccurrenceOrderPlugin(), |
40 |
| - // extract css into its own file |
41 |
| - new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')), |
42 |
| - // generate dist index.html with correct asset hash for caching. |
43 |
| - // you can customize output by editing /index.html |
44 |
| - // see https://github.com/ampedandwired/html-webpack-plugin |
45 |
| - new HtmlWebpackPlugin({ |
46 |
| - filename: process.env.NODE_ENV === 'testing' |
47 |
| - ? 'index.html' |
48 |
| - : config.build.index, |
49 |
| - template: 'index.html', |
50 |
| - inject: true, |
51 |
| - minify: { |
52 |
| - removeComments: true, |
53 |
| - collapseWhitespace: true, |
54 |
| - removeAttributeQuotes: true |
55 |
| - // more options: |
56 |
| - // https://github.com/kangax/html-minifier#options-quick-reference |
57 |
| - }, |
58 |
| - // necessary to consistently work with multiple chunks via CommonsChunkPlugin |
59 |
| - chunksSortMode: 'dependency' |
60 |
| - }), |
61 |
| - // split vendor js into its own file |
62 |
| - new webpack.optimize.CommonsChunkPlugin({ |
63 |
| - name: 'vendor', |
64 |
| - minChunks: function (module, count) { |
65 |
| - // any required modules inside node_modules are extracted to vendor |
66 |
| - return ( |
67 |
| - module.resource && |
68 |
| - /\.js$/.test(module.resource) && |
69 |
| - module.resource.indexOf( |
70 |
| - path.join(__dirname, '../node_modules') |
71 |
| - ) === 0 |
72 |
| - ) |
73 |
| - } |
74 |
| - }), |
75 |
| - // extract webpack runtime and module manifest to its own file in order to |
76 |
| - // prevent vendor hash from being updated whenever app bundle is updated |
77 |
| - new webpack.optimize.CommonsChunkPlugin({ |
78 |
| - name: 'manifest', |
79 |
| - chunks: ['vendor'] |
80 |
| - }) |
81 |
| - ] |
82 |
| -}) |
83 |
| - |
84 |
| -if (config.build.productionGzip) { |
85 |
| - var CompressionWebpackPlugin = require('compression-webpack-plugin') |
| 5 | +base.entry = { |
| 6 | + lib: './src/main.js' |
| 7 | +} |
86 | 8 |
|
87 |
| - webpackConfig.plugins.push( |
88 |
| - new CompressionWebpackPlugin({ |
89 |
| - asset: '[path].gz[query]', |
90 |
| - algorithm: 'gzip', |
91 |
| - test: new RegExp( |
92 |
| - '\\.(' + |
93 |
| - config.build.productionGzipExtensions.join('|') + |
94 |
| - ')$' |
95 |
| - ), |
96 |
| - threshold: 10240, |
97 |
| - minRatio: 0.8 |
98 |
| - }) |
99 |
| - ) |
| 9 | +base.output = { |
| 10 | + path: config.build.assetsRoot, |
| 11 | + publicPath: config.build.assetsPublicPath, |
| 12 | + filename: 'vue-button.js', |
| 13 | + library: 'VueButton', |
| 14 | + libraryTarget: 'umd' |
100 | 15 | }
|
101 | 16 |
|
| 17 | +var webpackConfig = Object.assign({}, base) |
| 18 | + |
| 19 | +webpackConfig.devtool = '#source-map' |
| 20 | +webpackConfig.plugins = (webpackConfig.plugins || []).concat([ |
| 21 | + new webpack.DefinePlugin({ |
| 22 | + 'process.env': { |
| 23 | + NODE_ENV: '"production"' |
| 24 | + } |
| 25 | + }), |
| 26 | + new webpack.optimize.UglifyJsPlugin({ |
| 27 | + compress: { warnings: false } |
| 28 | + }), |
| 29 | + new webpack.optimize.OccurenceOrderPlugin(), |
| 30 | +]) |
| 31 | + |
102 | 32 | module.exports = webpackConfig
|
0 commit comments