1 | var path = require('path');
|
2 | var webpack = require('webpack');
|
3 | var merge = require('webpack-merge');
|
4 | var autoprefixer = require('autoprefixer');
|
5 | var WebpackShellPlugin = require('webpack-shell-plugin')
|
6 | var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
|
7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
|
8 | var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
9 | var utils = require('./utils');
|
10 | var vueLoaderConfig = require('./vue-loader.conf');
|
11 | var getBaseConfig = require('./config');
|
12 |
|
13 | var isProduction = process.env.NODE_ENV === 'production'
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | module.exports = function(params){
|
21 |
|
22 | var config = getBaseConfig(params);
|
23 |
|
24 | return {
|
25 | output: {
|
26 |
|
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 |
|
45 | new webpack.ContextReplacementPlugin(/moment[\\/]locale$/, /^\.\/(zh-cn)$/),
|
46 |
|
47 | new ExtractTextPlugin({
|
48 | filename: '[name].css',
|
49 | allChunks: true,
|
50 | disable: false,
|
51 | }),
|
52 |
|
53 |
|
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 |
|
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 | }
|