2018-04-17 21:38:56 +00:00
|
|
|
/* eslint-disable */
|
|
|
|
const path = require( 'path' );
|
|
|
|
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
|
|
|
|
var NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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])/,
|
|
|
|
( match, letter ) => letter.toUpperCase()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-16 14:59:03 +00:00
|
|
|
const gutenbergEntries = [
|
2018-04-17 21:38:56 +00:00
|
|
|
'blocks',
|
|
|
|
'components',
|
|
|
|
'editor',
|
|
|
|
'utils',
|
|
|
|
'data',
|
|
|
|
'viewport',
|
|
|
|
'core-data',
|
|
|
|
'plugins',
|
|
|
|
'edit-post',
|
2018-05-16 14:59:03 +00:00
|
|
|
'core-blocks',
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const gutenbergPackages = [
|
|
|
|
'date',
|
2018-05-21 15:26:04 +00:00
|
|
|
'dom',
|
2018-05-16 14:59:03 +00:00
|
|
|
'element',
|
2018-07-14 09:20:10 +00:00
|
|
|
'keycodes',
|
|
|
|
'deprecated',
|
2018-05-16 14:59:03 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const wordPressPackages = [
|
|
|
|
'a11y',
|
|
|
|
'dom-ready',
|
2018-04-17 21:38:56 +00:00
|
|
|
'hooks',
|
|
|
|
'i18n',
|
2018-05-16 14:59:03 +00:00
|
|
|
'is-shallow-equal',
|
|
|
|
];
|
|
|
|
|
|
|
|
const coreGlobals = [
|
2018-04-17 21:38:56 +00:00
|
|
|
'api-request',
|
|
|
|
];
|
|
|
|
|
|
|
|
const externals = {
|
|
|
|
react: 'React',
|
|
|
|
'react-dom': 'ReactDOM',
|
|
|
|
tinymce: 'tinymce',
|
|
|
|
moment: 'moment',
|
|
|
|
jquery: 'jQuery',
|
|
|
|
};
|
|
|
|
|
2018-05-16 14:59:03 +00:00
|
|
|
[
|
|
|
|
...gutenbergEntries,
|
|
|
|
...gutenbergPackages,
|
|
|
|
...wordPressPackages,
|
|
|
|
...coreGlobals,
|
|
|
|
].forEach( ( name ) => {
|
2018-04-17 21:38:56 +00:00
|
|
|
externals[ `@wordpress/${ name }` ] = {
|
|
|
|
this: [ 'wp', camelCaseDash( name ) ],
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
const webpackConfig = {
|
|
|
|
mode: NODE_ENV,
|
2018-05-04 14:44:19 +00:00
|
|
|
entry: {
|
2018-05-11 16:13:57 +00:00
|
|
|
index: './client/index.js',
|
2018-06-26 14:49:42 +00:00
|
|
|
embedded: './client/embedded.js',
|
2018-05-04 14:44:19 +00:00
|
|
|
},
|
2018-04-17 21:38:56 +00:00
|
|
|
output: {
|
2018-05-07 15:10:42 +00:00
|
|
|
path: path.resolve( 'dist' ),
|
2018-05-04 14:44:19 +00:00
|
|
|
filename: '[name].js',
|
2018-05-07 15:10:42 +00:00
|
|
|
library: [ 'wc', '[name]' ],
|
2018-04-17 21:38:56 +00:00
|
|
|
libraryTarget: 'this',
|
|
|
|
},
|
|
|
|
externals,
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
exclude: /node_modules/
|
|
|
|
},
|
|
|
|
{
|
2018-05-28 10:55:19 +00:00
|
|
|
test: /\.(scss|css)$/,
|
2018-04-17 21:38:56 +00:00
|
|
|
use: ExtractTextPlugin.extract( {
|
|
|
|
fallback: 'style-loader',
|
2018-05-14 13:41:30 +00:00
|
|
|
use: [
|
|
|
|
'css-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
query: {
|
|
|
|
includePaths: [ 'client/stylesheets' ],
|
2018-05-25 19:34:35 +00:00
|
|
|
data: '@import "_colors"; @import "_breakpoints"; @import "_mixins";',
|
2018-05-14 13:41:30 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2018-04-17 21:38:56 +00:00
|
|
|
} ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-05-10 16:35:46 +00:00
|
|
|
resolve: {
|
|
|
|
extensions: [ '.json', '.js', '.jsx' ],
|
2018-05-11 16:13:57 +00:00
|
|
|
modules: [ path.join( __dirname, 'client' ), 'node_modules' ],
|
2018-05-10 16:35:46 +00:00
|
|
|
},
|
2018-04-17 21:38:56 +00:00
|
|
|
plugins: [
|
2018-06-26 14:49:42 +00:00
|
|
|
new ExtractTextPlugin( 'css/[name].css' ),
|
2018-04-17 21:38:56 +00:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2018-04-17 23:51:48 +00:00
|
|
|
if ( webpackConfig.mode !== 'production' ) {
|
|
|
|
webpackConfig.devtool = process.env.SOURCEMAP || 'source-map';
|
|
|
|
}
|
|
|
|
|
2018-04-17 21:38:56 +00:00
|
|
|
module.exports = webpackConfig;
|