-
create your new project directory and
cd
into it -
git init
-
create a simple
.gitignore
# .gitignore /node_modules/
-
npm init
and follow prompts -
install dev dependencies
npm install @babel/core @babel/preset-env autoprefixer babel-loader css-loader fibers file-loader mini-css-extract-plugin node-sass postcss-loader sass sass-loader style-loader url-loader webpack webpack-cli webpack-dev-server webpack-merge --save-dev
-
create basic
/src
subdirectory file structure- src/ - index.js styles/ - index.scss scripts/
-
In your root directory, create
webpack.common.js
// webpack.common.js const path = require("path"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const outputDir = "./dist"; module.exports = { entry: path.resolve(__dirname, "src", "index.js"), // output: { path: path.join(__dirname, outputDir), filename: "[name].js", publicPath: "/dist/" }, resolve: { extensions: [".js"] // if we were using React.js, we would include ".jsx" }, module: { rules: [ { test: /\.js$/, // if we were using React.js, we would use \.jsx?$/ use: { loader: "babel-loader", options: { presets: ["@babel/preset-env"], plugins: ["@babel/plugin-proposal-optional-chaining"], exclude: /node_modules/ } // if we were using React.js, we would include "react" } }, { test: /\.css$/, 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" } }, "css-loader", "postcss-loader" ] }, { test: /\.(png|jpe?g|gif)$/i, use: [ { loader: "file-loader", options: { // you can specify a publicPath here // by default it uses publicPath in webpackOptions.output name: "[name].[ext]", outputPath: "images/", publicPath: "images/" } } ] }, { test: /\.scss/, 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" } }, "css-loader", "sass-loader", "postcss-loader" ] } ] }, plugins: [ 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 }), require("autoprefixer") ] };
-
Create
webpack.dev.js
// wepack.dev.js const merge = require("webpack-merge"); const common = require("./webpack.common.js"); module.exports = merge(common, { mode: "development", devtool: "inline-source-map", devServer: { contentBase: "./", watchContentBase: true, open: "Google Chrome" } });
-
Create
webpack.prod.js
// webpack.prod.js const merge = require("webpack-merge"); const common = require("./webpack.common.js"); module.exports = merge(common, { mode: "production", devtool: "source-map" });
-
create
postcss.config.js
// postcss.config.js module.exports = { plugins: { autoprefixer: {} } };
-
add
browserlist
key and updatescripts
inpackage.json
// package.json "browserslist": [ "last 1 version", "> 1%", "maintained node versions", "not dead" ], "scripts": { "start": "webpack-dev-server --config webpack.dev.js", "webpack:watch": "webpack --watch --config webpack.dev.js", "webpack:build": "webpack --config webpack.prod.js --optimize-minimize" },
-
create
index.scss
in/src/styles
-
create
index.js
in/src
directory and import style/src/styles/index.scss
-
create
index.html
and importdist/main.css
anddist/main.js
appropriately
forked from mrcjbradley/js_project_skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
keely-lee/js_project_skeleton
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
basic directory structure and set up instructions for JS projects
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- JavaScript 83.3%
- CSS 11.1%
- HTML 5.6%