UNPKG

2.52 kBJavaScriptView Raw
1// const webpack = require('webpack');
2const path = require('path');
3const HtmlWebpackPlugin = require('html-webpack-plugin');
4const CleanWebpackPlugin = require('clean-webpack-plugin');
5const WebpackSftpClient = require('webpack-sftp-client');
6const fs = require('fs');
7const env = require('yargs').argv.env;
8
9process.env.NODE_ENV = 'production';
10
11const getEntry = () => {
12 const basePath = `${__dirname}/src/page/`;
13 return {
14 jsEntry: fs.readdirSync(basePath).reduce((map, dirName) => {
15 map[dirName] = `${basePath}${dirName}/index.js`;
16 return map;
17 }, {
18 zaro: ['react', 'react-dom', 'zaro']
19 }),
20 HtmlWebpackPlugin: fs.readdirSync(basePath).map(dirName => new HtmlWebpackPlugin({
21 filename: `html/${dirName}.html`,
22 chunks: [dirName, 'zaro'],
23 title: dirName,
24 template: 'example/src/template/basic.html',
25 }))
26 };
27};
28
29let envPlugin = [];
30let publicPath = '';
31if (env === 'dev2') {
32 envPlugin = [
33 new WebpackSftpClient({
34 port: '22',
35 host: '10.24.248.181',
36 username: 'root',
37 password: 'xxxxx',
38 path: path.resolve(__dirname, 'dist'),
39 remotePath: '/data/website/admin/boss/credit/',
40 verbose: true
41 })
42 ];
43 publicPath = '//o4jh53fw9.qnssl.com/dev2/admin/boss/credit/app/';
44} else if (env === 'test2') {
45 envPlugin = [
46 new WebpackSftpClient({
47 port: '22',
48 host: '10.43.1.10',
49 username: 'root',
50 password: 'xxxxxxxxx',
51 path: path.resolve(__dirname, 'dist'),
52 remotePath: '/data/website2/admin/boss/credit/',
53 verbose: true
54 })
55 ];
56 publicPath = '//o4jh53fw9.qnssl.com/test2/admin/boss/credit/app/';
57}
58
59const plugins = [
60 new CleanWebpackPlugin('dist'),
61].concat(envPlugin).concat(getEntry().HtmlWebpackPlugin);
62
63module.exports = {
64 entry: getEntry().jsEntry,
65 output: {
66 filename: '[name].[chunkhash].js',
67 path: path.resolve(__dirname, 'dist'),
68 publicPath
69 },
70 plugins,
71 module: {
72 rules: [{
73 test: /\.(js|jsx)$/,
74 exclude: /node_modules/,
75 use: [
76 'babel-loader'
77 ]
78 }, {
79 test: /\.css$/,
80 exclude: /node_modules/,
81 use: [
82 'style-loader',
83 'css-loader'
84 ]
85 }, {
86 test: /(\.jp(e)g|\.png|\.gif|\.svg)$/,
87 exclude: /node_modules/,
88 use: {
89 loader: 'file-loader',
90 query: {
91 name: '[name].[ext]'
92 },
93 }
94 }]
95 },
96 resolve: {
97 alias: {
98 zaro: path.resolve(__dirname, '../src/index')
99 }
100 },
101 devtool: 'source-map'
102};