/
hippy-webpack.android.js
112 lines (108 loc) 路 3.45 KB
/
hippy-webpack.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const HippyDynamicImportPlugin = require('@hippy/hippy-dynamic-import-plugin');
const pkg = require('../package.json');
const manifest = require('../dist/android/vendor-manifest.json');
const platform = 'android';
module.exports = {
mode: 'production',
bail: true,
entry: {
index: ['regenerator-runtime', path.resolve(pkg.main)],
},
output: {
filename: `[name].${platform}.js`,
path: path.resolve(`./dist/${platform}/`),
globalObject: '(0, eval)("this")',
// CDN path can be configured to load children bundles from remote server
// publicPath: 'https://xxx/hippy/hippyReactDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
}),
new CaseSensitivePathsPlugin(),
new webpack.DllReferencePlugin({
context: path.resolve(__dirname, '..'),
manifest,
}),
new HippyDynamicImportPlugin(),
// LimitChunkCountPlugin can control dynamic import ability
// Using 1 will prevent any additional chunks from being added
// new webpack.optimize.LimitChunkCountPlugin({
// maxChunks: 1,
// }),
// use SourceMapDevToolPlugin can generate sourcemap file
// new webpack.SourceMapDevToolPlugin({
// test: /\.(js|jsbundle|css|bundle)($|\?)/i,
// filename: '[file].map',
// }),
],
module: {
rules: [
{
test: /\.(jsx?)$/,
use: [
{
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
targets: {
chrome: 57,
},
},
],
],
plugins: [
['@babel/plugin-proposal-class-properties'],
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-transform-runtime', { regenerator: true }],
],
},
},
],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [{
loader: 'url-loader',
options: {
// if you would like to use base64 for picture, uncomment limit: true
// limit: true,
limit: 8192,
fallback: 'file-loader',
name: '[name].[ext]',
outputPath: 'assets/',
},
}],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
// if node_modules path listed below is not your repo directory, change it.
modules: [path.resolve(__dirname, '../node_modules')],
alias: (() => {
const aliases = {};
// If hippy-react was built exist then make a alias
// Remove the section if you don't use it
const hippyReactPath = path.resolve(__dirname, '../../../packages/hippy-react');
if (fs.existsSync(path.resolve(hippyReactPath, 'dist/index.js'))) {
console.warn(`* Using the @hippy/react in ${hippyReactPath}`);
aliases['@hippy/react'] = hippyReactPath;
} else {
console.warn('* Using the @hippy/react defined in package.json');
}
return aliases;
})(),
},
};