Don't say much nonsense, go straight to the actual combat!!!
1. Create a new folder on the desktop: webpack_test
2. Create a new folder under the Webpack_test folder demo01
3. Then create two JS files Main.js and Index.js files under the Demo01 folder
4. Write a function in Index.js and export
// declare a function and export it using export function Add (A, b) { + b);}
5. In Main.js, import the function in Index.js and call
Import {Add} from './index.js 'Add (3, 5); Add (78, 100);
6. Create a file under the root directory webpack_test index.html
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8"> <title>I study Webpack</title></Head><Body></Body></HTML>
7. Then create a new Webpack.config.js file under the root directory Webpack_test and write the configuration rule
Const PATH = require (' path ') Const Htmlwebpackplugin= Require (' Html-webpack-plugin ') Config={entry: { main:'./demo01/main.js '}, Output: {path:path.resolve (__dirname,' Dist ')//Specify the path to the export file filename:‘[Name]. js '//This is the same as the background color of the Chunk name, you can also specify the exit path as stipulated './[name].js ' exit will be in JS this folder}, module: {rules: [{test:/\.js$/, exclude:/node_modules/, Loader:' Babel-loader '}]}, plugins: [Newhtmlwebpackplugin ({filename:' Index_webpack.html ', Template:' Index.html '})]}module.exports= Config
8. Install various packages at the terminal
NPM init , &N Bsp Initialize
CNPM Install we Bpack--save-dev Download Webpack module
CNPM install babel-loader This package allows the use of babel and Webpack&nbs p; Convert JavaScript files
CNPM install babel-core &N Bsp to interpret JS files
Html-webpack-plugin Download the required plugins
9, then use Webpack compile, open the time to open the DIS directory index_webpack.html
Webpack-----The first chapter