Last active
March 29, 2020 13:14
-
-
Save szuc/a18e46e42b29d44b762c4bbfe43cf287 to your computer and use it in GitHub Desktop.
Quick compile and server Webpack config file for local Wordpress plugin development
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 | |
* Uses regular Webpack not Webpack-server. | |
* Uses BrowserSync to create a local server. | |
* Watch mode compiles and reloads on changes. | |
* Simplified version doesn't minify, etc.. to make process faster. | |
*/ | |
const path = require('path'); | |
const webpack = require('webpack'); | |
const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); | |
const MiniCssExtractPlugin = require("mini-css-extract-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: /\.s[c|a]ss$/, | |
use: [ | |
{ | |
loader: MiniCssExtractPlugin.loader, | |
}, | |
'css-loader', | |
'sass-loader', | |
], | |
}, | |
] | |
}, | |
plugins: [ | |
new MiniCssExtractPlugin({ | |
filename: "css/[name].css" | |
}), | |
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, | |
} | |
), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment