2018-09-26 14:23:55 +00:00
|
|
|
/** @format */
|
2018-07-23 20:14:40 +00:00
|
|
|
const path = require( 'path' );
|
|
|
|
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
|
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
2018-04-17 21:38:56 +00:00
|
|
|
|
|
|
|
const externals = {
|
2018-08-20 21:18:13 +00:00
|
|
|
'@woocommerce/components': { this: [ 'wc', 'components' ] },
|
2018-08-21 19:02:49 +00:00
|
|
|
'@wordpress/api-fetch': { this: [ 'wp', 'apiFetch' ] },
|
2018-07-23 20:14:40 +00:00
|
|
|
'@wordpress/blocks': { this: [ 'wp', 'blocks' ] },
|
|
|
|
'@wordpress/components': { this: [ 'wp', 'components' ] },
|
|
|
|
'@wordpress/compose': { this: [ 'wp', 'compose' ] },
|
|
|
|
'@wordpress/data': { this: [ 'wp', 'data' ] },
|
|
|
|
'@wordpress/editor': { this: [ 'wp', 'editor' ] },
|
|
|
|
'@wordpress/element': { this: [ 'wp', 'element' ] },
|
|
|
|
'@wordpress/hooks': { this: [ 'wp', 'hooks' ] },
|
|
|
|
'@wordpress/html-entities': { this: [ 'wp', 'htmlEntities' ] },
|
|
|
|
'@wordpress/i18n': { this: [ 'wp', 'i18n' ] },
|
|
|
|
'@wordpress/keycodes': { this: [ 'wp', 'keycodes' ] },
|
|
|
|
jquery: 'jQuery',
|
2018-04-17 21:38:56 +00:00
|
|
|
tinymce: 'tinymce',
|
|
|
|
moment: 'moment',
|
2018-07-23 20:14:40 +00:00
|
|
|
react: 'React',
|
|
|
|
'react-dom': 'ReactDOM',
|
2018-04-17 21:38:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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-08-20 21:18:13 +00:00
|
|
|
components: './client/components/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',
|
2018-07-23 20:14:40 +00:00
|
|
|
exclude: /node_modules/,
|
2018-04-17 21:38:56 +00:00
|
|
|
},
|
2018-09-24 15:36:35 +00:00
|
|
|
{ test: /\.md$/, use: 'raw-loader' },
|
2018-04-17 21:38:56 +00:00
|
|
|
{
|
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',
|
2018-07-30 14:05:22 +00:00
|
|
|
{
|
2018-07-20 03:40:15 +00:00
|
|
|
// postcss loader so we can use autoprefixer and theme Gutenberg components
|
|
|
|
loader: 'postcss-loader',
|
2018-07-30 14:05:22 +00:00
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
path: 'postcss.config.js',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-05-14 13:41:30 +00:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
query: {
|
2018-08-06 15:30:43 +00:00
|
|
|
includePaths: [ 'client/stylesheets/abstracts' ],
|
2018-07-23 20:14:40 +00:00
|
|
|
data:
|
2018-07-20 03:40:15 +00:00
|
|
|
'@import "_colors"; ' +
|
|
|
|
'@import "_variables"; ' +
|
|
|
|
'@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-07-20 03:40:15 +00:00
|
|
|
alias: {
|
|
|
|
'gutenberg-components': path.resolve( __dirname, 'node_modules/@wordpress/components/src' ),
|
|
|
|
},
|
2018-05-10 16:35:46 +00:00
|
|
|
},
|
2018-08-20 21:18:13 +00:00
|
|
|
plugins: [ 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;
|