forked from antixrist/node-phpmorphy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.babel.js
103 lines (99 loc) · 2.89 KB
/
webpack.config.babel.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
import fs from 'fs';
import path from 'path';
import glob from 'glob';
import BannerPlugin from 'webpack/lib/BannerPlugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import CircularDependencyPlugin from 'circular-dependency-plugin';
const cwd = process.cwd();
const isProduction = process.env.NODE_ENV == 'production';
const SCRIPTS_SOURCES = 'src';
const SCRIPTS_TARGET = 'build';
/** список npm-зависимостей */
const nodeModules = fs.readdirSync('node_modules').filter(x => !['.bin'].includes(x));
/**
* Основной webpack-конфиг.
* Настраивать можно любые опции - никаких побочных эффектов
* на остальных этапах настройки сборки быть не должно
*/
const config = {
context: cwd,
target: 'node',
recordsPath: path.join(cwd, SCRIPTS_TARGET, '_records'),
/**
* Ищем в директории-контексте вот такие файлы: `/\/[^_]{1}[^\\\\\/]*\.jsx?/`
* (т.е. js/jsx и имена у которых не начинаются с нижнего подчёркивания)
* и из полученного массива собираем формат для вебпака:
* { 'entry1': './entry1.js', 'entry2': './entry2.jsx' }
*/
entry: glob.sync(`${SCRIPTS_SOURCES}/!(_)*.js`).reduce((entries, file) => {
const entryName = path.basename(file, path.extname(file));
entries[entryName] = [
// 'babel-polyfill',
'./'+ file
];
return entries;
}, {}),
output: {
filename: `[name].js`,
chunkFilename: `[name].js`,
/** папка назначения */
path: path.join(cwd, SCRIPTS_TARGET),
libraryTarget: "commonjs-module"
},
node: {
__dirname: false,
__filename: false
},
devtool: 'source-map',
resolve: {
extensions: ['.js', '.json', '.json5', '.node'],
modules: ['node_modules'],
alias: {}
},
resolveLoader: {
moduleExtensions: ['-loader']
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
}
],
},
externals: [
function (context, request, cb) {
const pathStart = request.split('/')[0];
if (nodeModules.indexOf(pathStart) >= 0) {
return cb(null, "commonjs " + request);
}
cb();
}
],
watchOptions: {
aggregateTimeout: 200,
},
plugins: [
new CopyWebpackPlugin([{
context: SCRIPTS_SOURCES,
from: '**/*.!(js)',
to: ''
}]),
new CircularDependencyPlugin({ failOnError: false })
].concat(isProduction ? [] : [
new BannerPlugin({
banner: `require('source-map-support').install({ environment: 'node' });`,
raw: true,
entryOnly: false
})
]),
stats: {
colors: true,
chunks: false,
modules: false,
origins: false,
entrypoints: true,
}
};
export default config;