Last active
August 18, 2019 14:11
-
-
Save gnosis23/78cfa972980c96d1b06fc61a573189b6 to your computer and use it in GitHub Desktop.
Webpack React App
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
Show hidden characters
{ | |
"presets": ["@babel/preset-env", "@babel/preset-react"] | |
} |
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
{ | |
"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" | |
} | |
} |
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
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