Last active
January 27, 2019 14:39
-
-
Save Fake51/99b6069b190b90a755e310cea1b45275 to your computer and use it in GitHub Desktop.
babel react webpack build
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
#package.json | |
{ | |
"dependencies": { | |
"@babel/core": "^7.2.2", | |
"@babel/preset-env": "^7.3.1", | |
"@babel/preset-react": "^7.0.0", | |
"autoprefixer": "^9.4.6", | |
"babel-loader": "^8.0.5", | |
"css-loader": "^2.1.0", | |
"mini-css-extract-plugin": "^0.5.0", | |
"node-sass": "^4.11.0", | |
"postcss-loader": "^3.0.0", | |
"react": "^16.7.0", | |
"react-dom": "^16.7.0", | |
"react-router": "^4.3.1", | |
"sass-loader": "^7.1.0", | |
"webpack": "^4.29.0", | |
"webpack-cli": "^3.2.1" | |
}, | |
"scripts": { | |
"c": "webpack", | |
"w": "webpack -w" | |
}, | |
"devDependencies": {}, | |
"babel": { | |
"presets": [ | |
"@babel/env", | |
"@babel/react" | |
] | |
} | |
} | |
# webpack.config.js | |
const path = require('path'), | |
MiniCssExtractPlugin = require("mini-css-extract-plugin"); | |
module.exports = { | |
mode: "development", | |
entry: [ | |
'./assets/js/app.jsx', | |
'./assets/sass/main.scss', | |
], | |
output: { | |
path: path.resolve(__dirname, 'public/js'), | |
filename: 'bundle.js', | |
publicPath: '/' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.jsx?$/, | |
use: 'babel-loader', | |
}, | |
{ | |
test: /\.(scss|css)$/, | |
use: [ | |
MiniCssExtractPlugin.loader, | |
{ | |
loader: "css-loader", | |
options: { | |
minimize: { | |
safe: true | |
} | |
} | |
}, | |
{ | |
loader: "postcss-loader", | |
options: { | |
autoprefixer: { | |
browsers: ["last 2 versions"] | |
}, | |
}, | |
}, | |
{ | |
loader: "sass-loader", | |
options: {} | |
} | |
], | |
} | |
], | |
}, | |
plugins: [ | |
new MiniCssExtractPlugin({ | |
filename: "[name].bundle.css", | |
chunkFilename: "[id].css" | |
}) | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment