UNPKG

2.71 kBJavaScriptView Raw
1var utils = require('../libs/utils')
2var webpack = require('webpack')
3var config = require('../config')
4var merge = require('webpack-merge')
5var baseWebpackConfig = require('./webpack.wx-base.conf')
6var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
7
8var path = require('path')
9var ExtractTextPlugin = require('extract-text-webpack-plugin')
10var CopyWebpackPlugin = require('copy-webpack-plugin-hash')
11var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
12
13
14module.exports = function(entry) {
15 return merge(baseWebpackConfig, {
16 entry: entry,
17 module: {
18 rules: utils.styleLoaders({
19 sourceMap: config.dev.cssSourceMap,
20 extract: true
21 })
22 },
23 // cheap-module-eval-source-map is faster for development
24 // devtool: '#cheap-module-eval-source-map',
25 devtool: '#source-map',
26 output: {
27 path: config.paths['wx-dist'],
28 filename: utils.assetsPath('js/[name].js'),
29 chunkFilename: utils.assetsPath('js/[id].js')
30 },
31 plugins: [
32 new webpack.DefinePlugin({
33 'process.env': config.dev.env
34 }),
35
36 // copy from ./webpack.prod.conf.js
37 // extract css into its own file
38 new ExtractTextPlugin({
39 // filename: utils.assetsPath('css/[name].[contenthash].css')
40 filename: utils.assetsPath('css/[name].wxss')
41 }),
42 // Compress extracted CSS. We are using this plugin so that possible
43 // duplicated CSS from different components can be deduped.
44 new OptimizeCSSPlugin({
45 cssProcessorOptions: {
46 safe: true
47 }
48 }),
49 new webpack.optimize.CommonsChunkPlugin({
50 name: 'vendor',
51 minChunks: function(module, count) {
52 // any required modules inside node_modules are extracted to vendor
53 return (
54 module.resource &&
55 /\.js$/.test(module.resource) &&
56 module.resource.indexOf('node_modules') >= 0
57 ) || count >= 2
58 }
59 }),
60 new webpack.optimize.CommonsChunkPlugin({
61 name: 'manifest',
62 chunks: ['vendor']
63 }),
64 // copy custom static assets
65 new CopyWebpackPlugin([{
66 from: config.paths['wx-assets'],
67 to: config.paths['wx-assets-dist'],
68 ignore: ['.*']
69 }]),
70
71 // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
72 // new webpack.HotModuleReplacementPlugin(),
73 new webpack.NoEmitOnErrorsPlugin(),
74 // https://github.com/ampedandwired/html-webpack-plugin
75 // new HtmlWebpackPlugin({
76 // filename: 'index.html',
77 // template: 'index.html',
78 // inject: true
79 // }),
80 new FriendlyErrorsPlugin()
81 ]
82 })
83};