|
1
|
|
|
/** |
|
2
|
|
|
* Webpack Configuration |
|
3
|
|
|
* |
|
4
|
|
|
* Working of a Webpack can be very simple or complex. This is an intenally simple |
|
5
|
|
|
* build configuration. |
|
6
|
|
|
* |
|
7
|
|
|
* Webpack basics — If you are new the Webpack here's all you need to know: |
|
8
|
|
|
* 1. Webpack is a module bundler. It bundles different JS modules together. |
|
9
|
|
|
* 2. It needs and entry point and an ouput to process file(s) and bundle them. |
|
10
|
|
|
* 3. By default it only understands common JavaScript but you can make it |
|
11
|
|
|
* understand other formats by way of adding a Webpack loader. |
|
12
|
|
|
* 4. In the file below you will find an entry point, an ouput, and a babel-loader |
|
13
|
|
|
* that tests all .js files excluding the ones in node_modules to process the |
|
14
|
|
|
* ESNext and make it compatible with older browsers i.e. it converts the |
|
15
|
|
|
* ESNext (new standards of JavaScript) into old JavaScript through a loader |
|
16
|
|
|
* by Babel. |
|
17
|
|
|
* |
|
18
|
|
|
* TODO: Instructions. |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.0.0 |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
const paths = require( './paths' ); |
|
|
|
|
|
|
24
|
|
|
const autoprefixer = require( 'autoprefixer' ); |
|
|
|
|
|
|
25
|
|
|
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' ); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
// Extract style.css for both editor and frontend styles. |
|
28
|
|
|
const blocksCSSPlugin = new ExtractTextPlugin( { |
|
|
|
|
|
|
29
|
|
|
filename: './gutenberg/dist/blocks.style.build.css', |
|
30
|
|
|
} ); |
|
31
|
|
|
|
|
32
|
|
|
// Extract editor.css for editor styles. |
|
33
|
|
|
const editBlocksCSSPlugin = new ExtractTextPlugin( { |
|
|
|
|
|
|
34
|
|
|
filename: './gutenberg/dist/blocks.editor.build.css', |
|
35
|
|
|
} ); |
|
36
|
|
|
|
|
37
|
|
|
// Configuration for the ExtractTextPlugin — DRY rule. |
|
38
|
|
|
const extractConfig = { |
|
|
|
|
|
|
39
|
|
|
use: [ |
|
40
|
|
|
// "postcss" loader applies autoprefixer to our CSS. |
|
41
|
|
|
{ loader: 'raw-loader' }, |
|
42
|
|
|
{ |
|
43
|
|
|
loader: 'postcss-loader', |
|
44
|
|
|
options: { |
|
45
|
|
|
ident: 'postcss', |
|
46
|
|
|
plugins: [ |
|
47
|
|
|
autoprefixer( { |
|
48
|
|
|
browsers: [ |
|
49
|
|
|
'>1%', |
|
50
|
|
|
'last 4 versions', |
|
51
|
|
|
'Firefox ESR', |
|
52
|
|
|
'not ie < 9', // React doesn't support IE8 anyway |
|
53
|
|
|
], |
|
54
|
|
|
flexbox: 'no-2009', |
|
55
|
|
|
} ), |
|
56
|
|
|
], |
|
57
|
|
|
}, |
|
58
|
|
|
}, |
|
59
|
|
|
// "sass" loader converst SCSS to CSS. |
|
60
|
|
|
{ |
|
61
|
|
|
loader: 'sass-loader', |
|
62
|
|
|
options: { |
|
63
|
|
|
// Add common CSS file for variables and mixins. |
|
64
|
|
|
data: '@import "./gutenberg/src/common.scss";\n', |
|
65
|
|
|
outputStyle: 'nested', |
|
66
|
|
|
}, |
|
67
|
|
|
}, |
|
68
|
|
|
], |
|
69
|
|
|
}; |
|
70
|
|
|
|
|
71
|
|
|
// Export configuration. |
|
72
|
|
|
module.exports = { |
|
73
|
|
|
entry: { |
|
74
|
|
|
'./gutenberg/dist/blocks.build': paths.pluginBlocksJs, // 'name' : 'path/file.ext'. |
|
75
|
|
|
}, |
|
76
|
|
|
output: { |
|
77
|
|
|
// Add /* filename */ comments to generated require()s in the output. |
|
78
|
|
|
pathinfo: true, |
|
79
|
|
|
// The dist folder. |
|
80
|
|
|
path: paths.pluginDist, |
|
81
|
|
|
filename: '[name].js', // [name] = './dist/blocks.build' as defined above. |
|
82
|
|
|
}, |
|
83
|
|
|
// You may want 'eval' instead if you prefer to see the compiled output in DevTools. |
|
84
|
|
|
devtool: 'cheap-eval-source-map', |
|
85
|
|
|
module: { |
|
86
|
|
|
rules: [ |
|
87
|
|
|
{ |
|
88
|
|
|
test: /\.(js|jsx|mjs)$/, |
|
89
|
|
|
exclude: /(node_modules|bower_components)/, |
|
90
|
|
|
use: { |
|
91
|
|
|
loader: 'babel-loader', |
|
92
|
|
|
options: { |
|
93
|
|
|
|
|
94
|
|
|
// This is a feature of `babel-loader` for webpack (not Babel itself). |
|
95
|
|
|
// It enables caching results in ./node_modules/.cache/babel-loader/ |
|
96
|
|
|
// directory for faster rebuilds. |
|
97
|
|
|
cacheDirectory: true, |
|
98
|
|
|
}, |
|
99
|
|
|
}, |
|
100
|
|
|
}, |
|
101
|
|
|
{ |
|
102
|
|
|
test: /style\.s?css$/, |
|
103
|
|
|
exclude: /(node_modules|bower_components)/, |
|
104
|
|
|
use: blocksCSSPlugin.extract( extractConfig ), |
|
105
|
|
|
}, |
|
106
|
|
|
{ |
|
107
|
|
|
test: /editor\.s?css$/, |
|
108
|
|
|
exclude: /(node_modules|bower_components)/, |
|
109
|
|
|
use: editBlocksCSSPlugin.extract( extractConfig ), |
|
110
|
|
|
}, |
|
111
|
|
|
], |
|
112
|
|
|
}, |
|
113
|
|
|
// Add plugins. |
|
114
|
|
|
plugins: [ blocksCSSPlugin, editBlocksCSSPlugin ], |
|
115
|
|
|
stats: 'minimal', |
|
116
|
|
|
// stats: 'errors-only', |
|
117
|
|
|
// Add externals. |
|
118
|
|
|
externals: { |
|
119
|
|
|
react: 'React', |
|
120
|
|
|
'react-dom': 'ReactDOM', |
|
121
|
|
|
ga: 'ga', // Old Google Analytics. |
|
122
|
|
|
gtag: 'gtag', // New Google Analytics. |
|
123
|
|
|
jquery: 'jQuery', // import $ from 'jquery' // Use the WordPress version. |
|
124
|
|
|
}, |
|
125
|
|
|
}; |
|
126
|
|
|
|