-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
108 lines (104 loc) · 3.49 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
104
105
106
107
108
import glob from 'glob';
import path from 'path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
//import webpack from 'webpack';
//import PolyfillsPlugin from 'webpack-polyfills-plugin';
//const MinifyPlugin = require('babel-minify-webpack-plugin');
const SRC_RESOURCES_DIR = './src/main/resources';
const SRC_ASSETS_DIR = `${SRC_RESOURCES_DIR}/assets`;
const DST_RESOURCES_DIR = './build/resources/main';
const DST_ASSETS_DIR = `${DST_RESOURCES_DIR}/assets`;
const ASSETS_ES6_GLOB = glob.sync(`${SRC_ASSETS_DIR}/**/*.{es,es6,jsx}`);
const ES6_GLOB = glob.sync(`${SRC_RESOURCES_DIR}/**/*.{es,es6,jsx}`, { absolute: false, ignore: ASSETS_ES6_GLOB });
const entry = ES6_GLOB.reduce((entries, e) => Object.assign(entries, {
[e.replace(`${SRC_RESOURCES_DIR}/`, '').replace(/\.(es6?|jsx)/, '.js')]: [
// TypeError: Cannot read property "__core-js_shared__" from undefined (com.enonic.xp.resource.ResourceProblemException)
// var store = global[SHARED] || (global[SHARED] = {});
//'core-js/fn/map',
e
]
}), {});
//entry['assets/js/scripts.js'] = `${SRC_ASSETS_DIR}/js/scripts.es6`;
const WEBPACK_CONFIG = {
entry,
externals: [
/\/lib\/(enonic|xp)\/.+/
],
devtool: false, // Don't waste time generating source-maps
output: {
path: path.join(__dirname, DST_RESOURCES_DIR), // Must be absolute
filename: '[name]',
libraryTarget: 'commonjs'
},
mode: 'production',
module: {
rules: [
{
test: /\.(es6?|jsx?)$/,
exclude: /node_modules/, // Avoid $export is not a function when transform-runtime
loader: 'babel-loader',
options: {
babelrc: false,
compact: false,
minified: false,
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-object-assign',
//'@babel/plugin-transform-regenerator',
//'@babel/plugin-transform-runtime',
'array-includes'
],
presets: [
[
'@babel/preset-env', {
useBuiltIns: false // false means polyfill not required runtime
}
],
'@babel/preset-react'
]
}
}
] // loaders
}, // module
/*node: {
console: false,
global: true, // Needed by babel-polyfill, but didn't help :(
process: true,
__filename: "mock",
__dirname: "mock",
Buffer: true,
setImmediate: true
},*/
plugins: [
new CopyWebpackPlugin([
{ from: 'babel-standalone/', to: 'assets/babel-standalone/' },
{ from: 'bootstrap/dist/', to: 'assets/bootstrap/' },
{ from: 'react/umd/', to: 'assets/react/' },
{ from: 'react-bootstrap/dist/', to: 'assets/react-bootstrap/' },
{ from: 'react-dom/umd/', to: 'assets/react-dom/' }
], {
context: path.resolve(__dirname, 'node_modules')
})
/*{
apply: compiler => {
compiler.parser.plugin('expression global', () => {
this.state.module.addVariable('global', "(function() { return this; }()) || Function('return this')()");
return true;
});
}
},
new webpack.ProvidePlugin({
//Map: 'core-js/fn/map'
//Map: 'imports-loader?this=>global!exports-loader?global.Map!core-js/fn/map'
Map: 'es6-map' // Cannot read property "call" from undefined
//Map: 'es6-map/polyfill'
}),
new PolyfillsPlugin([
'Map'
]),
new MinifyPlugin({ //minifyOpts
}, { //pluginOpts
}) // MinifyPlugin*/
] // plugins
};
export default WEBPACK_CONFIG;