This is my first Webpack app
- Run
mkdir webpack
to create webpack dir. - Change dir
cd webpack
- Run
npm init -y
to createpackage.json
file - Run
npm install webpack webpack-cli --save-dev
to instal webpack - In package.json file remove
"main": "index.js",
- In package.json file add
"private": true,
- Add
import _ from 'lodash';
onindex.js
file. - Add
<script src="main.js"></script>
inindex.html
file. - Run
npm install --save lodash
- Run
npx webpack
, which will take our script atsrc/index.js
as the entry point, and will generatedist/main.js
as the output.
- Create
webpack.config.js
file in the root directory. - Paste the code below in the
webpack.config.js
file
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
};
- Run
npx webpack --config webpack.config.js
- Add this line
"test": "echo \"Error: no test specified\" && exit 1",
in package.json file. - Remove this line
"test": "echo \"Error: no test specified\" && exit 1"
in package.json file. - Add this line
"build": "webpack"
17 Lastly run thisnpm run build
and see if your code is running.