This repository has been archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80f5076
commit 3900278
Showing
17 changed files
with
9,468 additions
and
13,809 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* global process, module, require */ | ||
|
||
const path = require( 'path' ); | ||
const CleanWebpackPlugin = require( 'clean-webpack-plugin' ); | ||
const CopyWebpackPlugin = require( 'copy-webpack-plugin' ); | ||
const FixStyleOnlyEntriesPlugin = require( 'webpack-fix-style-only-entries' ); | ||
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' ); | ||
const StyleLintPlugin = require( 'stylelint-webpack-plugin' ); | ||
const WebpackBar = require( 'webpackbar' ); | ||
|
||
const isProduction = 'production' === process.env.NODE_ENV; | ||
|
||
// Config files. | ||
const settings = require( './webpack.settings.js' ); | ||
|
||
/** | ||
* Configure entries. | ||
*/ | ||
const configureEntries = () => { | ||
const entries = {}; | ||
|
||
for ( const [ key, value ] of Object.entries( settings.entries ) ) { | ||
entries[ key ] = path.resolve( process.cwd(), value ); | ||
} | ||
|
||
return entries; | ||
}; | ||
|
||
module.exports = { | ||
entry: configureEntries(), | ||
output: { | ||
path: path.resolve( process.cwd(), settings.paths.dist.base ), | ||
filename: settings.filename.js, | ||
}, | ||
|
||
// Console stats output. | ||
// @link https://webpack.js.org/configuration/stats/#stats | ||
stats: settings.stats, | ||
|
||
// External objects. | ||
externals: { | ||
jquery: 'jQuery', | ||
}, | ||
|
||
// Performance settings. | ||
performance: { | ||
maxAssetSize: settings.performance.maxAssetSize, | ||
}, | ||
|
||
// Build rules to handle asset files. | ||
module: { | ||
rules: [ | ||
// Lint JS. | ||
{ | ||
test: /\.js$/, | ||
enforce: 'pre', | ||
loader: 'eslint-loader', | ||
options: { | ||
fix: true | ||
} | ||
}, | ||
|
||
// Scripts. | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: [ | ||
{ | ||
loader: 'babel-loader', | ||
options: { | ||
presets: [ '@babel/preset-env' ], | ||
cacheDirectory: true, | ||
sourceMap: ! isProduction, | ||
}, | ||
}, | ||
], | ||
}, | ||
|
||
// Styles. | ||
{ | ||
test: /\.css$/, | ||
include: path.resolve( process.cwd(), settings.paths.src.css ), | ||
use: [ | ||
{ | ||
loader: MiniCssExtractPlugin.loader, | ||
}, | ||
{ | ||
loader: 'css-loader', | ||
options: { | ||
sourceMap: ! isProduction, | ||
// We copy fonts etc. using CopyWebpackPlugin. | ||
url: false, | ||
}, | ||
}, | ||
{ | ||
loader: 'postcss-loader', | ||
options: { | ||
sourceMap: ! isProduction, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
|
||
plugins: [ | ||
|
||
// Remove the extra JS files Webpack creates for CSS entries. | ||
// This should be fixed in Webpack 5. | ||
new FixStyleOnlyEntriesPlugin( { | ||
silent: true, | ||
} ), | ||
|
||
// Clean the `dist` folder on build. | ||
new CleanWebpackPlugin(), | ||
|
||
// Extract CSS into individual files. | ||
new MiniCssExtractPlugin( { | ||
filename: settings.filename.css, | ||
chunkFilename: '[id].css', | ||
} ), | ||
|
||
// Copy static assets to the `dist` folder. | ||
new CopyWebpackPlugin( [ | ||
{ | ||
from: settings.copyWebpackConfig.from, | ||
to: settings.copyWebpackConfig.to, | ||
context: path.resolve( process.cwd(), settings.paths.src.base ), | ||
}, | ||
] ), | ||
|
||
// Lint CSS. | ||
new StyleLintPlugin( { | ||
context: path.resolve( process.cwd(), settings.paths.src.css ), | ||
files: '**/*.css', | ||
} ), | ||
|
||
// Fancy WebpackBar. | ||
new WebpackBar(), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* global module, require */ | ||
|
||
const merge = require( 'webpack-merge' ); | ||
const common = require( './webpack.common.js' ); | ||
const BrowserSyncPlugin = require( 'browser-sync-webpack-plugin' ); | ||
|
||
// Config files. | ||
const settings = require( './webpack.settings.js' ); | ||
|
||
module.exports = merge( common, { | ||
mode: 'development', | ||
devtool: 'inline-cheap-module-source-map', | ||
plugins: [ | ||
// Run BrowserSync. | ||
new BrowserSyncPlugin( | ||
{ | ||
host: settings.BrowserSyncConfig.host, | ||
port: settings.BrowserSyncConfig.port, | ||
proxy: settings.BrowserSyncConfig.proxy, | ||
open: settings.BrowserSyncConfig.open, | ||
files: settings.BrowserSyncConfig.files, | ||
}, | ||
{ | ||
injectCss: true, | ||
reload: false, | ||
} | ||
), | ||
], | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* global module, require */ | ||
|
||
const merge = require( 'webpack-merge' ); | ||
const common = require( './webpack.common.js' ); | ||
const TerserPlugin = require( 'terser-webpack-plugin' ); | ||
|
||
module.exports = merge( common, { | ||
mode: 'production', | ||
|
||
optimization: { | ||
minimizer: [ | ||
new TerserPlugin( { | ||
cache: true, | ||
parallel: true, | ||
sourceMap: false, | ||
terserOptions: { | ||
parse: { | ||
// We want terser to parse ecma 8 code. However, we don't want it | ||
// to apply any minfication steps that turns valid ecma 5 code | ||
// into invalid ecma 5 code. This is why the 'compress' and 'output' | ||
// sections only apply transformations that are ecma 5 safe | ||
// https://github.com/facebook/create-react-app/pull/4234 | ||
ecma: 8 | ||
}, | ||
compress: { | ||
ecma: 5, | ||
warnings: false, | ||
// Disabled because of an issue with Uglify breaking seemingly valid code: | ||
// https://github.com/facebook/create-react-app/issues/2376 | ||
// Pending further investigation: | ||
// https://github.com/mishoo/UglifyJS2/issues/2011 | ||
comparisons: false, | ||
// Disabled because of an issue with Terser breaking valid code: | ||
// https://github.com/facebook/create-react-app/issues/5250 | ||
// Pending futher investigation: | ||
// https://github.com/terser-js/terser/issues/120 | ||
inline: 2 | ||
}, | ||
output: { | ||
ecma: 5, | ||
comments: false | ||
}, | ||
ie8: false | ||
} | ||
} ) | ||
], | ||
}, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* global module */ | ||
|
||
// Webpack settings exports. | ||
module.exports = { | ||
entries: { | ||
// JS files. | ||
'admin': './assets/js/admin/admin.js', | ||
'frontend': './assets/js/frontend/frontend.js', | ||
'shared': './assets/js/shared/shared.js', | ||
|
||
// CSS files. | ||
'admin-style': './assets/css/admin/admin-style.css', | ||
'editor-style': './assets/css/frontend/editor-style.css', | ||
'shared-style': './assets/css/shared/shared-style.css', | ||
'style': './assets/css/frontend/style.css', | ||
}, | ||
filename: { | ||
js: 'js/[name].js', | ||
css: 'css/[name].css' | ||
}, | ||
paths: { | ||
src: { | ||
base: './assets/', | ||
css: './assets/css/', | ||
js: './assets/js/' | ||
}, | ||
dist: { | ||
base: './dist/', | ||
clean: ['./images', './css', './js'] | ||
}, | ||
}, | ||
stats: { | ||
// Copied from `'minimal'`. | ||
all: false, | ||
errors: true, | ||
maxModules: 0, | ||
modules: true, | ||
warnings: true, | ||
// Our additional options. | ||
assets: true, | ||
errorDetails: true, | ||
excludeAssets: /\.(jpe?g|png|gif|svg|woff|woff2)$/i, | ||
moduleTrace: true, | ||
performance: true | ||
}, | ||
copyWebpackConfig: { | ||
from: '**/*.{jpg,jpeg,png,gif,svg,eot,ttf,woff,woff2}', | ||
to: '[path][name].[ext]' | ||
}, | ||
BrowserSyncConfig: { | ||
host: 'localhost', | ||
port: 3000, | ||
proxy: 'http://tenup-scaffold.test', | ||
open: false, | ||
files: [ | ||
'**/*.php', | ||
'dist/js/**/*.js', | ||
'dist/css/**/*.css', | ||
'dist/svg/**/*.svg', | ||
'dist/images/**/*.{jpg,jpeg,png,gif}', | ||
'dist/fonts/**/*.{eot,ttf,woff,woff2,svg}' | ||
] | ||
}, | ||
performance: { | ||
maxAssetSize: 100000 | ||
}, | ||
manifestConfig: { | ||
basePath: '' | ||
}, | ||
}; |
Oops, something went wrong.