Skip to content

Instantly share code, notes, and snippets.

@gnosis23
Last active August 18, 2019 14:11
Show Gist options
  • Save gnosis23/78cfa972980c96d1b06fc61a573189b6 to your computer and use it in GitHub Desktop.
Save gnosis23/78cfa972980c96d1b06fc61a573189b6 to your computer and use it in GitHub Desktop.
Webpack React App
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
{
"name": "rrrreact",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-loader": "^8.0.6",
"css-loader": "^3.2.0",
"html-webpack-plugin": "^3.2.0",
"less": "^3.10.1",
"less-loader": "^5.0.0",
"mini-css-extract-plugin": "^0.8.0",
"postcss-loader": "^3.0.0",
"style-loader": "^1.0.0",
"url-loader": "^2.1.0",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.6"
},
"dependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
}
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [{
loader: 'url-loader',
options: { limit: 10240 },
}]
},
{
test: /\.less$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it uses publicPath in webpackOptions.output
publicPath: '../',
hmr: process.env.NODE_ENV === 'development',
},
},
{
loader: 'css-loader',
options: {
modules: {
mode: 'local',
localIdentName: '[name]__[hash:base64:5]__[local]',
context: path.resolve(__dirname, 'src'),
hashPrefix: 'my-custom-hash',
},
}
},
'less-loader',
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(__dirname, "src", "index.html")
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// all options are optional
filename: '[name].css',
chunkFilename: '[id].css',
ignoreOrder: false, // Enable to remove warnings about conflicting order
}),
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment