forked from front/gutenberg-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
147 lines (139 loc) · 3.73 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* External dependencies
*/
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const { resolve } = require('path');
const extractCSS = new ExtractTextPlugin('./css/style.css');
const extractBLCSS = new ExtractTextPlugin('./css/block-library/style.css');
// const PostCssWrapper = require('postcss-wrapper-loader');
// const StringReplacePlugin = require('string-replace-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
/**
* Given a string, returns a new string with dash separators converedd to
* camel-case equivalent. This is not as aggressive as `_.camelCase` in
* converting to uppercase, where Lodash will convert letters following
* numbers.
*
* @param {string} string Input dash-delimited string.
*
* @return {string} Camel-cased string.
*/
function camelCaseDash (string) {
return string.replace(
/-([a-z])/g,
(match, letter) => letter.toUpperCase()
);
}
const externals = {
react: 'React',
'react-dom': 'ReactDOM',
moment: 'moment',
jquery: 'jQuery',
};
const alias = {};
[
'api-fetch',
'url',
].forEach(name => {
externals[ `@wordpress/${name}` ] = {
this: [ 'wp', camelCaseDash(name) ],
};
});
module.exports = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devtool: 'source-map',
entry: './src/js/index.js',
output: {
filename: 'js/gutenberg-js.js',
path: resolve(__dirname, 'build'),
libraryTarget: 'this',
},
externals,
resolve: {
modules: [
__dirname,
resolve(__dirname, 'node_modules'),
],
alias,
},
module: {
rules: [
{
test: /\.js$/,
include: [
/src/,
/node_modules\/@wordpress/,
],
use: 'babel-loader',
},
{
test: /\.js$/,
oneOf: [
{
resourceQuery: /\?source=node_modules/,
use: 'babel-loader',
},
{
loader: 'path-replace-loader',
options: {
path: resolve(__dirname, 'node_modules/@wordpress'),
replacePath: resolve(__dirname, 'src/js/gutenberg-overrides/@wordpress'),
},
},
],
},
/* {
test: /editor\.s?css$/,
include: [
/block-library/,
],
use: mainCSSExtractTextPlugin.extract({
use: [
{
// removing .gutenberg class in editor.scss files
loader: StringReplacePlugin.replace({
replacements: [ {
pattern: /.gutenberg /ig,
// replacement: () => (''),
replacement: () => ('.gutenberg__editor'),
} ],
}),
},
...extractConfig.use,
],
}),
},*/
{
test: /style\.s?css$/,
use: extractCSS.extract({
fallback: 'style-loader', // creates style nodes from JS strings
use: [
{ loader: 'css-loader' }, // translates CSS into CommonJS
{ loader: 'sass-loader' }, // compiles Sass to CSS
],
}),
},
{
test: /block-library\.s?css$/,
use: extractBLCSS.extract({
fallback: 'style-loader', // creates style nodes from JS strings
use: [
{ loader: 'css-loader' }, // translates CSS into CommonJS
{ loader: 'sass-loader' }, // compiles Sass to CSS
],
}),
},
],
},
plugins: [
extractCSS,
extractBLCSS,
// wrapping editor style with .gutenberg__editor class
// new PostCssWrapper('./css/block-library/edit-blocks.css', '.gutenberg__editor'),
// new StringReplacePlugin(),
new CleanWebpackPlugin(['build']),
],
stats: {
children: false,
},
};