UNPKG

4.01 kBJavaScriptView Raw
1'use strict';
2const fs = require('fs');
3const path = require('path');
4const webpack = require('webpack');
5const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
6const MiniCssExtractPlugin = require("mini-css-extract-plugin")
7
8const getClientEnvironment = require('./env');
9const paths = require('./paths');
10
11const env = getClientEnvironment();
12const appPackageJson = require(paths.appPackageJson);
13const appDirectory = fs.realpathSync(process.cwd());
14module.exports = {
15 mode: 'production',
16 devtool: 'cheap-module-source-map',
17 optimization: {
18 minimizer: []
19 },
20 entry: [
21 paths.appIndexJs
22 ],
23 output: {
24 filename: appPackageJson.name + '.js',
25 path: path.join(appDirectory, "/build/dev/"),
26 library: "MKApp_" + appPackageJson.name.replace(/-/g, '_'),
27 libraryTarget: "umd"
28 },
29 resolve: {
30 extensions: [".js"]
31 },
32 externals: {
33 "react": {
34 root: 'React',
35 commonjs2: 'react',
36 commonjs: 'react',
37 amd: 'react'
38 },
39 "react-dom": {
40 root: 'ReactDOM',
41 commonjs2: 'react-dom',
42 commonjs: 'react-dom',
43 amd: 'react-dom'
44 },
45 "immutable": {
46 root: 'Immutable',
47 commonjs2: 'immutable',
48 commonjs: 'immutable',
49 amd: 'immutable'
50 },
51 "moment": "moment",
52 "mk-sdk": "MK",
53 "mk-app-loader": {
54 root: ["MK", "appLoader"],
55 commonjs: "MK.appLoader",
56 commonjs2: "MK.appLoader",
57 amd: "MK.appLoader"
58 },
59 "mk-utils": {
60 root: ["MK", "utils"],
61 commonjs2: "MK.utils",
62 amd: "MK.utils",
63 commonjs: "MK.utils",
64 },
65 "mk-component": {
66 root: ["MK", "component"],
67 commonjs2: "MK.component",
68 amd: "MK.component",
69 commonjs: "MK.component"
70 },
71 "mk-meta-engine": {
72 commonjs: ["MK", "metaEngine"],
73 commonjs2: "MK.metaEngine",
74 amd: "MK.metaEngine",
75 root: "MK.metaEngine"
76 },
77 "mk-aar-form": "mk-aar-form",
78 "mk-aar-grid": "mk-aar-grid",
79 "echarts": "echarts"
80 },
81 module: {
82 rules: [{
83 test: /\.(js|jsx|mjs)$/,
84 include: paths.appSrc,
85 exclude: paths.appNodeModules,
86 loader: require.resolve('babel-loader'),
87 options: {
88 babelrc: false,
89 presets: [
90 'env',
91 'stage-2',
92 'react',
93 ],
94 plugins: [
95 ["transform-runtime", {
96 "helpers": false,
97 "polyfill": false,
98 "regenerator": true,
99 "moduleName": "babel-runtime"
100 }],
101 'add-module-exports',
102 'transform-decorators-legacy'
103 ],
104 compact: true,
105 },
106 }, {
107 test: /\.css$/,
108 use: [MiniCssExtractPlugin.loader, 'css-loader']
109 }, {
110 test: /\.less$/,
111 use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader']
112
113 }, {
114 test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif|mp4|webm)(\?\S*)?$/,
115 use: {
116 loader: 'file-loader',
117 options: {
118 name: '[name].[ext]',
119 limit: 8192
120 }
121 }
122 }],
123 },
124 plugins: [
125 new webpack.DefinePlugin(env.stringified),
126 //大小写匹配
127 new CaseSensitivePathsPlugin(),
128 new MiniCssExtractPlugin({ filename: appPackageJson.name + '.css' })
129 ],
130 node: {
131 dgram: 'empty',
132 fs: 'empty',
133 net: 'empty',
134 tls: 'empty',
135 child_process: 'empty',
136 }
137};