Skip to content

Commit a9096fd

Browse files
authored
Merge pull request #199 from AElfProject/feature/esm
feat: esm
2 parents b086c81 + 8071cbe commit a9096fd

33 files changed

+429
-427
lines changed

.eslintrc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
"class-methods-use-this": "off",
3535
"no-plusplus": "off",
3636
"implicit-arrow-linebreak": "off",
37-
"object-curly-newline": "off"
37+
"object-curly-newline": "off",
38+
"import/extensions": [
39+
"error",
40+
"ignorePackages",
41+
{
42+
"js": "always",
43+
"json": "always"
44+
}
45+
],
46+
"operator-linebreak": ["warn", "after"]
3847
}
3948
}

.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
3-
HUSKY_GIT_PARAMS=$1 node scripts/verify-commit-msg.js
3+
HUSKY_GIT_PARAMS=$1 node scripts/verify-commit-msg.cjs

build/utils.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
/**
2-
* @file utils
3-
* @author atom-yang
4-
* @date 2019-06-28
5-
*/
6-
const path = require('path');
1+
import path from 'path';
72

8-
module.exports.ROOT = path.resolve(__dirname, '..');
3+
export const ROOT = path.resolve(process.cwd(), '.');
94

10-
module.exports.OUTPUT_PATH = path.resolve(__dirname, '..', 'dist/');
5+
export const OUTPUT_PATH = path.resolve(process.cwd(), '.', 'dist/');
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,22 @@
55

66
/* eslint-env node */
77

8-
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
8+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
99
const DeadCodePlugin = require('webpack-deadcode-plugin');
1010
const { merge } = require('webpack-merge');
11-
const nodeConfig = require('./webpack.node');
11+
const nodeConfig = require('./webpack.node.js');
1212
const browserConfig = require('./webpack.browser');
1313

1414
const unusedAnalyzeConfig = {
1515
patterns: ['src/**/*.*'],
1616
globOptions: {
17-
ignore: [
18-
'**/*.md',
19-
'node_modules/**/*'
20-
]
17+
ignore: ['**/*.md', 'node_modules/**/*']
2118
}
2219
};
2320

2421
module.exports = merge(process.env.RUNTIME_ENV === 'node' ? nodeConfig : browserConfig, {
2522
plugins: [
26-
new BundleAnalyzerPlugin({analyzerMode: 'static', generateStatsFile: true}),
23+
new BundleAnalyzerPlugin({ analyzerMode: 'static', generateStatsFile: true }),
2724
new DeadCodePlugin(unusedAnalyzeConfig)
2825
]
2926
});

build/webpack.browser.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
* @author atom-yang
44
*/
55

6-
/* eslint-env node */
7-
const { merge } = require('webpack-merge');
8-
const webpack = require('webpack');
9-
const baseConfig = require('./webpack.common');
10-
const { OUTPUT_PATH } = require('./utils');
6+
import { merge } from 'webpack-merge';
7+
import webpack from 'webpack';
8+
import baseConfig from './webpack.common.js';
9+
import { OUTPUT_PATH } from './utils.js';
10+
import { createRequire } from 'module';
11+
12+
const require = createRequire(import.meta.url);
1113

1214
const browserConfig = {
1315
mode: 'production',
@@ -63,11 +65,10 @@ const browserConfig = {
6365
new webpack.ProvidePlugin({
6466
Buffer: ['buffer', 'Buffer']
6567
}),
66-
// fix "process is not defined" error:
6768
new webpack.ProvidePlugin({
6869
process: 'process/browser'
6970
})
7071
]
7172
};
7273

73-
module.exports = merge(baseConfig, browserConfig);
74+
export default merge(baseConfig, browserConfig);

build/webpack.common.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
/**
2-
* @file common config
3-
* @author atom-yang
4-
*/
5-
61
/* eslint-env node */
7-
const path = require('path');
8-
const webpack = require('webpack');
9-
const { ROOT } = require('./utils');
10-
const { version, name } = require(path.resolve(ROOT, './package.json'));
2+
import path from 'path';
3+
import webpack from 'webpack';
4+
import { ROOT } from './utils.js';
5+
const pkg = await import(path.resolve(ROOT, './package.json'), {
6+
assert: { type: 'json' }
7+
});
8+
const { version, name } = pkg;
119

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

@@ -43,4 +41,4 @@ const baseConfig = {
4341
}
4442
};
4543

46-
module.exports = baseConfig;
44+
export default baseConfig;

build/webpack.esModule.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file node config
3+
* @author atom-yang
4+
*/
5+
6+
/* eslint-env node */
7+
import { merge } from 'webpack-merge';
8+
import baseConfig from './webpack.common.js';
9+
import { OUTPUT_PATH } from './utils.js';
10+
11+
const nodeConfig = {
12+
mode: 'production',
13+
output: {
14+
path: OUTPUT_PATH,
15+
filename: 'aelf.esm.js',
16+
libraryTarget: 'module'
17+
},
18+
experiments: {
19+
outputModule: true
20+
},
21+
resolve: {
22+
alias: {},
23+
fallback: {
24+
crypto: 'crypto-browserify',
25+
stream: 'stream-browserify',
26+
https: false,
27+
http: false,
28+
child_process: false,
29+
fs: false,
30+
url: false
31+
}
32+
}
33+
};
34+
35+
export default merge(baseConfig, nodeConfig);

build/webpack.node.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*/
55

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

1111
const nodeConfig = {
1212
mode: 'production',
@@ -18,11 +18,6 @@ const nodeConfig = {
1818
},
1919
libraryExport: 'default'
2020
},
21-
resolve: {
22-
alias: {
23-
// 'scryptsy$': '../scrypt-polyfill.js',
24-
}
25-
},
2621
target: 'node',
2722
optimization: {
2823
removeEmptyChunks: true,
@@ -33,4 +28,4 @@ const nodeConfig = {
3328
}
3429
};
3530

36-
module.exports = merge(baseConfig, nodeConfig);
31+
export default merge(baseConfig, nodeConfig);

0 commit comments

Comments
 (0)