-
Notifications
You must be signed in to change notification settings - Fork 57
/
webpack.config.js
95 lines (85 loc) · 2.41 KB
/
webpack.config.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
const path = require('path');
const sass = require( 'node-sass' );
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = ( env = {} ) => {
return {
mode: (() => {
if ( env.production ) return 'production'
else return 'development'
})(),
devtool: 'cheap-source-map',
entry: {
editor_backend: './js/src/editor/backend/index.js',
editor_frontend: './js/src/editor/frontend/index.js',
client_backend: './js/src/client/backend/index.js',
client_frontend: './js/src/client/frontend/index.js'
},
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, './js/dist')
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
},
},
},
],
},
plugins: [
new CopyWebpackPlugin([
{
from: './css/src/frontend/',
to: '../../css/dist/frontend.min.css', // relative to ./js/dist/
transform: ( content, path ) => {
// CopyWebpackPlugin - simply copies files over.
// transform - perform actions over files while copping.
// 1. Compile SCSS into CSS with https://github.com/sass/node-sass
const result = sass.renderSync({
file: path,
outputStyle: 'compressed',
sourceMapEmbed: (() => {
if ( env.production ) return false
else return true
})(),
});
// 2. Prepare result:
const css = result.css.toString();
return css;
},
}
]),
new CopyWebpackPlugin([
{
from: './css/src/builder/',
to: '../../css/dist/builder.min.css', // relative to ./js/dist/
transform: ( content, path ) => {
// CopyWebpackPlugin - simply copies files over.
// transform - perform actions over files while copping.
// 1. Compile SCSS into CSS with https://github.com/sass/node-sass
const result = sass.renderSync({
file: path,
outputStyle: 'compressed',
sourceMapEmbed: (() => {
if ( env.production ) return false
else return true
})(),
});
// 2. Prepare result:
const css = result.css.toString();
return css;
},
}
]),
]
};
};