forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack.js
77 lines (72 loc) · 1.88 KB
/
pack.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
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const getWebpackConfig = require('./webpack/prod');
const { logger } = require('./utils');
const distPath = path.join(process.cwd(), 'dist');
const args = process.argv.slice(2);
const minimize = args.indexOf('minimize') > -1;
const config = getWebpackConfig({ minimize });
config.entry = {
next: ['./index.scss', './index.js'],
'next-with-locales': './index-with-locales.js',
'next-noreset': './index-noreset.scss',
};
config.output = Object.assign({}, config.output, {
path: distPath,
publicPath: '/dist/',
library: 'Next',
libraryTarget: 'umd',
});
config.externals = [
{
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
},
{
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
},
{
moment: {
root: 'moment',
commonjs2: 'moment',
commonjs: 'moment',
amd: 'moment',
},
},
];
config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));
// eslint-disable-next-line handle-callback-err
webpack(config, (err, stats) => {
logger.info(
stats.toString({
colors: true,
chunks: false,
modules: false,
hash: false,
usedExports: false,
version: false,
})
);
try {
if (minimize) {
fs.unlinkSync(path.join(distPath, 'next-noreset.min.js'));
} else {
fs.unlinkSync(path.join(distPath, 'next-noreset.js'));
}
} catch (e) {
logger.warn(
'remove next-noreset.js or next-noreset.min.js failed: ',
e
);
}
});