webpack common configuration

webpack.config.js

const path = require('path');
const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin');
const vueLoaderPlugin = require('vue-loader/lib/plugin'); //引入这行

module.exports = {
    entry: './src/main.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'boundle.js'
    },
    mode: 'development',
    devServer: {
        open: true,automatically open a browser//
        Port: 3000, // run the port number 
        ContentBase: 'src', // specify the directory with 
        Hot: to true , // enable hot update 
        OpenPage: 'index.html' // set the default start page 
    }, 
    plugins: [ 
        // Configuration widget node 
        new new webpack.HotModuleReplacementPlugin (), // hot update 
        new new vueLoaderPlugin (),
         new new htmlWebpackPlugin ({
             // create a plug-in memory to generate HTML pages 
            // and the packaged boundle.js automatically injected into the html page 
            template : path.join (__ dirname, './src/index.html' ), 
            filename:'index.html' 
        }) 
    ], 
    Module1: { 
        the rules: [ 
            // third party modules matching rule 
            { 
                Test: /\.css$/ , 
                use: [
                     'style-Loader' , 
                    { 
                        Loader: 'CSS-Loader' , 
                        Options: { 
                            sourceMap: to true 
                        } 
                    }, 
                    { 
                        Loader: 'postcss-Loader' ,  
                        Options: {
                            ident: 'postcss' , 
                            sourceMap: to true , 
                            plugins: (Loader) => { 
                                the require ( 'autoprefixer') ({overrideBrowserslist: [ '> 0.15% in the CN' ]}) 
                            } 
                        } 
                    } 
                ] 
            }, 
            { 
                // process the image path the Loader 
                Test: /\.(jpg|png|gif|bmp|jpeg)$/ , 
                use: { 
                    Loader: 'URL-Loader' ,
                    Options: { 
                        limit:  8501,
                         // hash - the original name of the picture. Original image suffix 
                        name: '[the hash:. 8] - [name] [EXT].' 
                    } 
                } 
            }, 
            { 
                Test: /\.(ttf|eot|svg|woff|woff2)$/ , 
                use: [ 'url- Loader ' ]
                 // use: { 
                //      Loader:' URL-Loader ', 
                //      Options: { 

                //      } 
                // } 
            },
             // Test:. / \ (TTF | EOT | WOFF | woff2 | SVG) $ /, 
            //use: [ 'file-loader' ] // 1 move your resources to the output directory 2. Return url final introduction of resources.
             {
                Test: /\.js$/ , 
                the exclude: / (the node_modules | bower_components) /, // exclude both inside JS not compiled 
                use: { 
                    Loader: 'Babel-Loader' , 
                } 
            }, 
            { 
                Test: / \. $ VUE / , 
                use: [ 
                    { 
                        Loader: 'VUE-Loader' , 
                    } 
                ] 
            }, 
            { 
                Test: /\.scss$/ , 
                use: ["style-loader", "css-loader", "sass-loader"]
            }
        ]
    }
};

package.json (VUE school)

{
  "name": "webpack-test",
  "version": "1.0.0",
  "description": "test",
  "main": "main.js",
  "dependencies": {
    "jquery": "^3.4.1",
    "node-sass": "^4.12.0",
    "vue": "^2.6.10",
    "webpack-dev-server": "^3.8.0"
  },
  "devDependencies": {
    "autoprefixer": "^9.6.1",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-0": "^6.24.1",
    "css-loader": "^3.2.0",
    "file-loader": "^4.2.0",
    "html-webpack-plugin": "^3.2.0",
    "postcss-loader": "^3.0.0",
    "sass-loader": "^8.0.0",
    "style-loader": "^1.0.0",
    "url-loader": "^2.1.0",
    "vue-loader": "^15.7.1",
    "vue-router": "^3.1.3",
    "vue-template-compiler": "^2.6.10",
    "vuex": "^3.1.1",
    "webpack": "^4.39.3",
    "webpack-cli": "^3.3.8"
  },
  "scripts": {
    "dev2": "webpack-dev-server --open --port 3000 --contentBase src --hot",
    "dev": "webpack-dev-server",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

 

Guess you like

Origin www.cnblogs.com/llcdbk/p/11563971.html