Skip to content

Commit

Permalink
feat(hermes): demo build script support hermes
Browse files Browse the repository at this point in the history
  • Loading branch information
ilikethese committed Dec 28, 2023
1 parent 6a1c29f commit c57bc36
Show file tree
Hide file tree
Showing 18 changed files with 1,655 additions and 23 deletions.
4 changes: 3 additions & 1 deletion driver/js/examples/hippy-react-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"hippy:vendor": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.ios-vendor.js --config ./scripts/hippy-webpack.android-vendor.js",
"hippy:build": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.ios.js --config ./scripts/hippy-webpack.android.js",
"web:dev": "npm run hippy:dev & node ./scripts/env-polyfill.js webpack serve --config ./scripts/hippy-webpack.web-renderer.dev.js",
"web:build": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.web-renderer.js"
"web:build": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.web-renderer.js",
"hippy:vendor:hermes": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.hermes.ios-vendor.js --config ./scripts/hippy-webpack.hermes.android-vendor.js",
"hippy:build:hermes": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.hermes.ios.js --config ./scripts/hippy-webpack.hermes.android.js"
},
"keywords": [
"Hippy",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');

const platform = 'android';
const engine = 'hermes';

module.exports = {
mode: 'production',
bail: true,
entry: {
vendor: [path.resolve(__dirname, './vendor.js')],
},
output: {
filename: `[name].${platform}.js`,
path: path.resolve(`./dist/${platform}_${engine}/`),
globalObject: '(0, eval)("this")',
library: 'hippyReactBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
}),
new CaseSensitivePathsPlugin(),
new webpack.DllPlugin({
context: path.resolve(__dirname, '..'),
path: path.resolve(__dirname, `../dist/${platform}/[name]-manifest.json`),
name: 'hippyReactBase',
}),
],
module: {
rules: [
{
test: /\.(js)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
chrome: 41,
},
},
],
],
plugins: [
['@babel/plugin-proposal-class-properties'],
],
},
},
],
},
],
},
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;
})(),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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';
const engine = 'hermes';

module.exports = {
mode: 'production',
bail: true,
entry: {
index: ['regenerator-runtime', path.resolve(pkg.main)],
},
output: {
filename: `[name].${platform}.js`,
path: path.resolve(`./dist/${platform}_${engine}/`),
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: 41,
},
},
],
],
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;
})(),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');

const platform = 'ios';
const engine = 'hermes';

module.exports = {
mode: 'production',
bail: true,
entry: {
vendor: [path.resolve(__dirname, './vendor.js')],
},
output: {
filename: `[name].${platform}.js`,
path: path.resolve(`./dist/${platform}_${engine}/`),
globalObject: '(0, eval)("this")',
library: 'hippyReactBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
}),
new CaseSensitivePathsPlugin(),
new webpack.DllPlugin({
context: path.resolve(__dirname, '..'),
path: path.resolve(__dirname, `../dist/${platform}/[name]-manifest.json`),
name: 'hippyReactBase',
}),
],
module: {
rules: [
{
test: /\.(jsx?)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
ios: 8,
chrome: 41,
},
},
],
],
plugins: [
['@babel/plugin-proposal-class-properties'],
],
},
},
],
},
],
},
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;
})(),
},
};
Loading

0 comments on commit c57bc36

Please sign in to comment.