Last active
February 18, 2021 09:25
-
-
Save olygood/c74cc4a7276806291c3858ed2e1cc42a to your computer and use it in GitHub Desktop.
webpack for .js and .scss
This file contains hidden or 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
npm init -y | |
npm i -D @babel/cli @babel/core @babel/preset-env babel-loader css-loader html-webpack-plugin style-loader webpack webpack-cli webpack-dev-server core-js@3 regenerator-runtime |
This file contains hidden or 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
/*webpack simple */ | |
const path = require("path"); | |
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
module.exports = { | |
entry: { | |
main: path.join(__dirname, "src/index.js") | |
}, | |
output: { | |
path: path.join(__dirname, "dist"), | |
filename: "[name].bundle.js" | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js/, | |
exclude: /(node_modules)/, | |
use: ["babel-loader"] | |
}, | |
{ | |
test: /\.css$/i, | |
use: ["style-loader", "css-loader"] | |
} | |
] | |
}, | |
plugins: [ | |
new HtmlWebpackPlugin({ | |
template: path.join(__dirname, "./src/index.html") | |
}) | |
], | |
stats: "minimal", | |
devtool: "source-map", | |
mode: "development", | |
devServer: { | |
open: false, | |
contentBase: "./dist", | |
inline: true, | |
port: 4000 | |
} | |
}; | |
/*--------------------------------------------------------------------------------------------*/ | |
/*webpack avec react*/ | |
const path = require("path"); | |
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
module.exports = { | |
entry: path.resolve(__dirname, "src/index.js"), | |
output: { | |
path: path.resolve(__dirname, "dist"), | |
filename: "[name].bundle.js" | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: ["babel-loader"] | |
}, | |
{ | |
test: /\.scss$/i, | |
use: ["style-loader","css-loader","sass-loader"] | |
} | |
] | |
}, | |
plugins: [ | |
new HtmlWebpackPlugin({ | |
template: path.resolve(__dirname, "src/index.html") | |
}) | |
], | |
devtool: "source-map", | |
mode: "development", | |
devServer: { | |
contentBase: path.resolve(__dirname, "./dist"), | |
inline: true, | |
open: true, | |
hot: true, | |
port: 4000 | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
npm init -y
npm i -D @babel/cli @babel/core @babel/preset-env babel-loader css-loader html-webpack-plugin style-loader webpack webpack-cli webpack-dev-server core-js@3 regenerator-runtime