Last active
March 29, 2020 13:19
-
-
Save szuc/3bc44468fe7d6b5b32a05d51d76148a7 to your computer and use it in GitHub Desktop.
Webpack config file for local Wordpress plugin development with more minification and backwards compatibility for more extensive testing.
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
/** | |
* Dev Webpack mode for cross-browser fixing | |
* Uses regular Webpack not Webpack-server. | |
* Uses BrowserSync to create a local server. | |
* Watch mode compiles and reloads on changes. | |
* Slower, css and js minification version. | |
*/ | |
const path = require('path') | |
const webpack = require('webpack') | |
const BrowserSyncPlugin = require('browser-sync-webpack-plugin') | |
const { CleanWebpackPlugin } = require('clean-webpack-plugin') | |
const MiniCssExtractPlugin = require("mini-css-extract-plugin") | |
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin") | |
const TerserPlugin = require('terser-webpack-plugin') | |
const postcss = require('postcss') | |
const postcssPresetEnv = require('postcss-preset-env') | |
const CopyPlugin = require('copy-webpack-plugin') | |
module.exports = { | |
mode: 'development', | |
entry: { | |
myApp_admin: "./src/scss/admin_styles.scss", | |
myApp: [ "./src/index.js" ], | |
}, | |
output: { | |
filename: 'js/[name].js', | |
path: path.resolve(__dirname, 'assets') | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: ['@babel/preset-env'], | |
} | |
} | |
}, | |
{ | |
test: /\.s[c|a]ss$/, | |
use: [ | |
MiniCssExtractPlugin.loader, | |
'css-loader', | |
{ | |
loader: 'postcss-loader', | |
options: { | |
ident: 'postcss', | |
plugins: [ | |
require('postcss-preset-env') | |
] | |
} | |
}, | |
'sass-loader' | |
] | |
} | |
] | |
}, | |
plugins: [ | |
new webpack.ProgressPlugin(), | |
new CleanWebpackPlugin(), | |
new MiniCssExtractPlugin({ | |
filename: 'css/[name].css' | |
}), | |
new CopyPlugin([ | |
{ | |
from: 'img/**/*', | |
to: 'img/[name].[ext]', | |
context: 'src/' | |
// dot: true, | |
// toType: 'dir', | |
} | |
]), | |
new BrowserSyncPlugin( | |
// BrowserSync options | |
{ | |
files: '**/*.php', | |
// browse to http://localhost:3000/ during development | |
host: 'localhost', | |
port: 3000, | |
proxy: 'http://yourlocalserver.dev/', | |
}, | |
// plugin options | |
{ | |
// reload: true, | |
// injectCss: true, // doesn't work | |
injectChanges: true | |
} | |
) | |
], | |
optimization: { | |
minimizer: [ | |
new OptimizeCSSAssetsPlugin({ | |
cssProcessorOptions: { | |
discardComments: true, | |
map: { | |
inline: false, | |
annotation: true | |
}, | |
safe: true | |
}, | |
}), | |
new TerserPlugin({ | |
parallel: true, | |
terserOptions: { | |
safari10: true | |
} | |
}) | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment