Webpack is a spinach website rental (e-217-1793-408) gulp almost automatic building tools, the function is still very powerful, able to handle image compression, can handle JS, can handle those pre-compiled language such as SASS|SCSS, CSS and so on, All thanks to a powerful loader function.
Prepare the article
Webpack is a tool that uses node's NPM package management tool to download and install: NPM install-g--save-dev webpack similar to this.
It mainly includes files: Webpack.config.js, Package.json (initialization automatically generated, there are many version related information, including the installation of loaders, etc.), import files, export files.
Inside the Webpack.config.js, the main code framework:
Const PATH = require (' path ');
Const Extracttextplugin = require (' Extract-text-webpack-plugin ');
?
Module.exports = {
? ? Entry: './src/main.js ',
? ? Output: {
? ? ? ? FileName: ' Bundle.js ',??????? The file name of the output
? ? ? ? Path:path.resolve (dirname, ' build ')//The directory where the output file resides
? ? },
? ? Devserver: {//Detect code changes and automatically recompile and refresh the browser automatically
? ? ? ? ContentBase:path.resolve (DirName, ' build ')//Set the root directory of the static resource
? ? },
? ? Module: {//How to work with different types of modules in a project
? ? ? ? Rules: [//To specify how to handle modules when different modules are created.
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Test:/(. jsx|. JS) $/,
? ? ? ? ? ? ? ? Use: {
? ? ? ? ? ? ? ? ? ? Loader: "Babel-loader",
? ? ? ? ? ? ? ? ? ? Options: {
? ? ? ? ? ? ? ? ? ? ? ? Presets: [
? ? ? ? ? ? ? ? ? ? ? ? ? ? "Env", "React"
? ? ? ? ? ? ? ? ? ? ? ? ]?
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? Exclude:path.resolve (__dirname, ' node_modules '),
? ? ? ? ? ? ? ? Include:path.resolve (__dirname, ' src '),
? ? ? ? ? ? },
? ? ? ? ? ? {//css individually packaged
? ? ? ? ? ? ? ? Test:/.scss/,
? ? ? ? ? ? ? ? Use:ExtractTextPlugin.extract ({
? ? ? ? ? ? ? ? ? ? Use: [{
? ? ? ? ? ? ? ? ? ? ? ? Loader: "Css-loader"
? ? ? ? ? ? ? ? ? ? },{
? ? ? ? ? ? ? ? ? ? ? ? Loader: ' Sass-loader '
? ? ? ? ? ? ? ? ? ? }],
? ? ? ? ? ? ? ? ? ? Fallback: "Style-loader"
? ? ? ? ? ? ? ? })
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Test:/.css$/,
? ? ? ? ? ? ? ? Use:ExtractTextPlugin.extract ({
? ? ? ? ? ? ? ? ? ? Use: [' Css-loader '],
? ? ? ? ? ? ? ? }),
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? Test:/. (png|jpg) $/,
? ? Loader: ' url-loader?limit=8192 ',
? ? }
? ? ? ? ]
? ? },
? ? Plugins: [
? ? ? ? New Extracttextplugin ({
? ? ? ? ? ? FileName: ' Main-page.css ',
? ? ? ? }),
? ? ]
};
Webpack Summary and spinach website rental