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