woocommerce/plugins/woocommerce-admin/webpack.config.js

133 lines
3.3 KiB
JavaScript
Raw Normal View History

/** @format */
/**
* External dependencies
*/
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
const { get } = require( 'lodash' );
const path = require( 'path' );
/**
* WordPress dependencies
*/
const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' );
const NODE_ENV = process.env.NODE_ENV || 'development';
2018-04-17 21:38:56 +00:00
const externals = {
'@wordpress/api-fetch': { this: [ 'wp', 'apiFetch' ] },
'@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' ] },
2018-04-17 21:38:56 +00:00
tinymce: 'tinymce',
moment: 'moment',
react: 'React',
'react-dom': 'ReactDOM',
2018-04-17 21:38:56 +00:00
};
const wcAdminPackages = {
components: './client/components',
'csv-export': './packages/csv-export',
currency: './packages/currency',
date: './packages/date',
navigation: './packages/navigation',
};
Object.keys( wcAdminPackages ).forEach( name => {
externals[ `@woocommerce/${ name }` ] = {
this: [ 'wc', name.replace( /-([a-z])/g, ( match, letter ) => letter.toUpperCase() ) ],
};
} );
2018-04-17 21:38:56 +00:00
const webpackConfig = {
mode: NODE_ENV,
entry: {
app: './client/index.js',
embedded: './client/embedded.js',
...wcAdminPackages,
},
2018-04-17 21:38:56 +00:00
output: {
filename: './dist/[name]/index.js',
path: __dirname,
library: [ 'wc', '[modulename]' ],
2018-04-17 21:38:56 +00:00
libraryTarget: 'this',
},
externals,
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
2018-04-17 21:38:56 +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',
use: [
'css-loader',
{
2018-07-20 03:40:15 +00:00
// postcss loader so we can use autoprefixer and theme Gutenberg components
loader: 'postcss-loader',
options: {
config: {
path: 'postcss.config.js',
},
},
},
{
loader: 'sass-loader',
query: {
includePaths: [ 'client/stylesheets/abstracts' ],
data:
2018-07-20 03:40:15 +00:00
'@import "_colors"; ' +
'@import "_variables"; ' +
'@import "_breakpoints"; ' +
'@import "_mixins"; ',
},
},
],
2018-04-17 21:38:56 +00:00
} ),
},
],
},
resolve: {
extensions: [ '.json', '.js', '.jsx' ],
modules: [
path.join( __dirname, 'client' ),
path.join( __dirname, 'packages' ),
'node_modules',
],
2018-07-20 03:40:15 +00:00
alias: {
'gutenberg-components': path.resolve( __dirname, 'node_modules/@wordpress/components/src' ),
},
},
plugins: [
new CustomTemplatedPathPlugin( {
modulename( outputPath, data ) {
const entryName = get( data, [ 'chunk', 'name' ] );
if ( entryName ) {
return entryName.replace( /-([a-z])/g, ( match, letter ) => letter.toUpperCase() );
}
return outputPath;
},
} ),
new ExtractTextPlugin( {
filename: './dist/[name]/style.css',
} ),
],
2018-04-17 21:38:56 +00:00
};
if ( webpackConfig.mode !== 'production' ) {
webpackConfig.devtool = process.env.SOURCEMAP || 'source-map';
}
2018-04-17 21:38:56 +00:00
module.exports = webpackConfig;