Skip to content

Commit

Permalink
Merge pull request #199 from AElfProject/feature/esm
Browse files Browse the repository at this point in the history
feat: esm
  • Loading branch information
hzz780 authored Nov 1, 2024
2 parents b086c81 + 8071cbe commit a9096fd
Show file tree
Hide file tree
Showing 33 changed files with 429 additions and 427 deletions.
11 changes: 10 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
"class-methods-use-this": "off",
"no-plusplus": "off",
"implicit-arrow-linebreak": "off",
"object-curly-newline": "off"
"object-curly-newline": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"js": "always",
"json": "always"
}
],
"operator-linebreak": ["warn", "after"]
}
}
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
HUSKY_GIT_PARAMS=$1 node scripts/verify-commit-msg.js
HUSKY_GIT_PARAMS=$1 node scripts/verify-commit-msg.cjs
11 changes: 3 additions & 8 deletions build/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* @file utils
* @author atom-yang
* @date 2019-06-28
*/
const path = require('path');
import path from 'path';

module.exports.ROOT = path.resolve(__dirname, '..');
export const ROOT = path.resolve(process.cwd(), '.');

module.exports.OUTPUT_PATH = path.resolve(__dirname, '..', 'dist/');
export const OUTPUT_PATH = path.resolve(process.cwd(), '.', 'dist/');
11 changes: 4 additions & 7 deletions build/webpack.analyze.js → build/webpack.analyze.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@

/* eslint-env node */

const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const DeadCodePlugin = require('webpack-deadcode-plugin');
const { merge } = require('webpack-merge');
const nodeConfig = require('./webpack.node');
const nodeConfig = require('./webpack.node.js');
const browserConfig = require('./webpack.browser');

const unusedAnalyzeConfig = {
patterns: ['src/**/*.*'],
globOptions: {
ignore: [
'**/*.md',
'node_modules/**/*'
]
ignore: ['**/*.md', 'node_modules/**/*']
}
};

module.exports = merge(process.env.RUNTIME_ENV === 'node' ? nodeConfig : browserConfig, {
plugins: [
new BundleAnalyzerPlugin({analyzerMode: 'static', generateStatsFile: true}),
new BundleAnalyzerPlugin({ analyzerMode: 'static', generateStatsFile: true }),
new DeadCodePlugin(unusedAnalyzeConfig)
]
});
15 changes: 8 additions & 7 deletions build/webpack.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* @author atom-yang
*/

/* eslint-env node */
const { merge } = require('webpack-merge');
const webpack = require('webpack');
const baseConfig = require('./webpack.common');
const { OUTPUT_PATH } = require('./utils');
import { merge } from 'webpack-merge';
import webpack from 'webpack';
import baseConfig from './webpack.common.js';
import { OUTPUT_PATH } from './utils.js';
import { createRequire } from 'module';

const require = createRequire(import.meta.url);

const browserConfig = {
mode: 'production',
Expand Down Expand Up @@ -63,11 +65,10 @@ const browserConfig = {
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
}),
// fix "process is not defined" error:
new webpack.ProvidePlugin({
process: 'process/browser'
})
]
};

module.exports = merge(baseConfig, browserConfig);
export default merge(baseConfig, browserConfig);
18 changes: 8 additions & 10 deletions build/webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* @file common config
* @author atom-yang
*/

/* eslint-env node */
const path = require('path');
const webpack = require('webpack');
const { ROOT } = require('./utils');
const { version, name } = require(path.resolve(ROOT, './package.json'));
import path from 'path';
import webpack from 'webpack';
import { ROOT } from './utils.js';
const pkg = await import(path.resolve(ROOT, './package.json'), {
assert: { type: 'json' }
});
const { version, name } = pkg;

const banner = `${name}.js v${version} \n(c) 2019-${new Date().getFullYear()} AElf \nReleased under MIT License`;

Expand Down Expand Up @@ -43,4 +41,4 @@ const baseConfig = {
}
};

module.exports = baseConfig;
export default baseConfig;
35 changes: 35 additions & 0 deletions build/webpack.esModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file node config
* @author atom-yang
*/

/* eslint-env node */
import { merge } from 'webpack-merge';
import baseConfig from './webpack.common.js';
import { OUTPUT_PATH } from './utils.js';

const nodeConfig = {
mode: 'production',
output: {
path: OUTPUT_PATH,
filename: 'aelf.esm.js',
libraryTarget: 'module'
},
experiments: {
outputModule: true
},
resolve: {
alias: {},
fallback: {
crypto: 'crypto-browserify',
stream: 'stream-browserify',
https: false,
http: false,
child_process: false,
fs: false,
url: false
}
}
};

export default merge(baseConfig, nodeConfig);
13 changes: 4 additions & 9 deletions build/webpack.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

/* eslint-env node */
const { merge } = require('webpack-merge');
const baseConfig = require('./webpack.common');
const { OUTPUT_PATH } = require('./utils');
import { merge } from 'webpack-merge';
import baseConfig from './webpack.common.js';
import { OUTPUT_PATH } from './utils.js';

const nodeConfig = {
mode: 'production',
Expand All @@ -18,11 +18,6 @@ const nodeConfig = {
},
libraryExport: 'default'
},
resolve: {
alias: {
// 'scryptsy$': '../scrypt-polyfill.js',
}
},
target: 'node',
optimization: {
removeEmptyChunks: true,
Expand All @@ -33,4 +28,4 @@ const nodeConfig = {
}
};

module.exports = merge(baseConfig, nodeConfig);
export default merge(baseConfig, nodeConfig);
Loading

0 comments on commit a9096fd

Please sign in to comment.