-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
67 lines (58 loc) · 1.77 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
const webpack = require( 'webpack' );
const path = require( 'path' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
/**
* CleanWebpackPlugin (ビルド先のほかのファイルを勝手に削除するやつ) はオフに。
*/
defaultConfig.plugins.shift();
let entryFiles = {};
let srcDir = 'js';
let distDir = 'js';
if ( 'guten' === process.env.TYPE ) {
srcDir = 'js/gutenberg';
distDir = 'js/gutenberg';
entryFiles = [ 'post_editor' ];
} else {
// asset.php 出力しない
for ( let i = 0; i < defaultConfig.plugins.length; i++ ) {
const pluginInstance = defaultConfig.plugins[ i ];
if ( 'DependencyExtractionWebpackPlugin' === pluginInstance.constructor.name ) {
defaultConfig.plugins.splice( i, i );
}
}
if ( 'front' === process.env.TYPE ) {
entryFiles = [ 'main', 'plugin/lazysizes', 'plugin/luminous' ];
} else if ( 'admin' === process.env.TYPE ) {
srcDir = 'js/admin';
distDir = 'js/admin';
entryFiles = [ 'customizer-controls', 'responsive-device-preview' ];
} else if ( 'guten' === process.env.TYPE ) {
entryFiles = [ 'guten_post' ];
}
}
const entryPoints = {};
entryFiles.forEach( ( name ) => {
entryPoints[ name ] = path.resolve( './src', srcDir, `${ name }.js` );
} );
// ソースマップファイルを生成しない。
delete defaultConfig.devtool;
/**
* exports
*/
module.exports = {
...defaultConfig, //@wordpress/scriptを引き継ぐ
mode: 'production', // より圧縮させる
entry: entryPoints,
output: {
path: path.resolve( './dist', distDir ),
filename: '[name].js',
},
resolve: {
alias: {
'@js': path.resolve( __dirname, 'src/js/' ),
},
},
plugins: [ ...defaultConfig.plugins, new webpack.EnvironmentPlugin( [ 'TYPE' ] ) ],
// performance: { hints: false },
// devtool: 'none',
};