UNPKG

4 kBJavaScriptView Raw
1var path = require('path');
2var webpack = require('webpack');
3var merge = require('webpack-merge');
4var autoprefixer = require('autoprefixer');
5var WebpackShellPlugin = require('webpack-shell-plugin')
6var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
7var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
8var ExtractTextPlugin = require("extract-text-webpack-plugin");
9var utils = require('./utils');
10var vueLoaderConfig = require('./vue-loader.conf');
11var getBaseConfig = require('./config');
12//是否正式环境
13var isProduction = process.env.NODE_ENV === 'production'
14// var isIOSApp = process.env.platform === 'ios';
15// var isANDROIDApp = process.env.platform === 'android';
16// var isBuildBeta = process.env.build_type === 'beta';
17// var isBuildOfficial = process.env.build_type === 'official';
18// console.log("hhahahhh--->" + utils.resolve('src'))
19
20module.exports = function(params){
21
22 var config = getBaseConfig(params);
23
24 return {
25 output: {
26 //path: params.root,
27 filename:'[name].js',
28 },
29 resolve: {
30 extensions: ['.js', '.vue', '.json', '.png', '.css', '.less'],
31 alias:config.alias,
32 },
33 plugins:[
34 new webpack.DefinePlugin({
35 'process.env': isProduction ? config.prod.env : config.dev.env,
36 }),
37 new webpack.LoaderOptionsPlugin({
38 options: {
39 postcss: function () {
40 return [ autoprefixer ];
41 },
42 }
43 }),
44 //优化moment
45 new webpack.ContextReplacementPlugin(/moment[\\/]locale$/, /^\.\/(zh-cn)$/),
46
47 new ExtractTextPlugin({
48 filename: '[name].css',
49 allChunks: true,
50 disable: false,
51 }),
52 //优化loadash
53 // new LodashModuleReplacementPlugin(),
54 //一坨必备的插件
55 new webpack.optimize.ModuleConcatenationPlugin(),
56 new webpack.NoEmitOnErrorsPlugin(),
57 new FriendlyErrorsPlugin(),
58
59 ],
60 module: {
61 rules: [
62 {
63 test: /\.vue$/,
64 loader: 'vue-loader',
65 options: vueLoaderConfig
66 },
67
68 {
69 test: /upaas-ui.src.*?js$/,
70 loader: 'babel-loader'
71 },
72 {
73 test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
74 loader: '@beisen/bsapp-file-loader',
75 query: {
76 isBsApp:true,
77 outputPath(url, filepath){
78 var p = filepath.replace(utils.resolve('.')+path.sep, '').replace('src'+path.sep, '');
79 var dir = path.dirname(p).replace(params.root, '');
80
81 if (filepath.indexOf('node_modules') > -1) {
82 return {
83 outputPath:'../../www/public/lib/assets',
84 url:'./assets/'+url,
85 fileName:url,
86 }
87 } else {
88 return {
89 outputPath:'./'+dir,
90 url:'./assets/'+url,
91 fileName:url,
92 }
93 }
94
95 },
96 name: '[name].[ext]',
97 useRelativePath:false,
98 }
99 },
100 {
101 test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
102 loader: '@beisen/bsapp-file-loader',
103 query: {
104 isBsApp:true,
105 outputPath(url, filepath){
106 var p = filepath.replace(utils.resolve('.')+path.sep, '').replace('src'+path.sep, '');
107 // var dir = path.dirname(p);
108 var dir = path.dirname(p).replace(params.root, '');
109 if (filepath.indexOf('node_modules') > -1) {
110 return {
111 outputPath:'../../www/public/lib/assets',
112 url:'./assets/'+url,
113 fileName:url,
114 }
115 } else {
116 return {
117 outputPath:'./'+dir,
118 url:url,
119 fileName:url,
120 }
121 }
122
123 },
124 name: '[name].[ext]',
125 useRelativePath:false,
126 }
127 }
128 ]
129 }
130 }
131}