WebPack mounted in the first mounting global npm i webpack - after the first installation g after installation becomes unnecessary to run in the project root npm i webpack catalog --save- dev mounted to project dependencies PS = " dist directory represents the product directly to the user-level directory syntax ul > li {10 * this is the first $ li} this is a fast syntax
Make a line of each color features are 4 steps installation package describes the init file npm - the y-new version of the node that will own the npm i jQuery -S installation jq saved to rely on the list went to the E: \ vuekaifa \ lib \ 05day- webpack- interlaced color> this directory to 05day -webpack- interlaced color directory == "New New index.html file in the src directory under the src directory create a file in the src directory mian.js src directory created imgs folder and js folder 05day -webpack- interlaced color directory ==> Create directory dist introduced jq introduced syntax file is in mian.js import ** ** from it is introduced into the module es6 embodiment 1 as import $ from 'jquery' attention to the case from the incoming file to know first is to look at their brothers and brothers directory directory to the parent directory to find and so on download jQuery i CNPM - S // achieve interlaced color functions $ ( Function () { $ ( . "Li: the ODD") CSS ( "background", "Red" ) }) in node.js, if you wrote $ const = The require ( "Jquery" ) Since the import es6 Taiwan advanced package guide the way the browser so it can not resolve from $ Import 'Jquery' report wrong so it is necessary to awaken the conversion webpack
Webpack configuration and operation webpack
2 Creating webpack.config.js document are as follows in the src module.exports = { entry: path.join (__ dirname, './mian.js'), // entry file using a file which to pack webpack Output: { / / output related configuration path: path.join (__ dirname, '. / dist'), // specify the packaged file to which the output directory (dist) go // filename: "testindex.js" // specified package good file name What is the name } } 3 so when the index was introduced in webpack we compiled js files on it <Script src = "../ dist / testindex.js"> </ Script> 4 run webpack conversion syntax is webpack. / compiled file path ./ path of the new file this command webpack run (focus) webpack./src/mian.js ./dist/testindex.js in dist in the file being compiled for testindex.js
webpack can handle problems
webpack capable of processing interdependencies between js file
webpack js able to handle the compatibility problems can be loaded into es5 es6 syntax grammar
We can see two ways of introducing jquery
const $=require("Jquery")
import $ from 'jquery'