• 比较实用的webpack配置代码


    var path = require('path');
    var webpack = require('webpack');
    var ExtractTextPlugin = require('extract-text-webpack-plugin'); //css单独打包
    var HtmlWebpackPlugin = require('html-webpack-plugin'); //生成html


    var ROOT_PATH = path.resolve(__dirname);
    var APP_PATH = path.resolve(ROOT_PATH, 'src'); //__dirname 中的src目录,以此类推
    var APP_FILE = path.resolve(APP_PATH, 'App'); //根目录文件app.js地址
    var BUILD_PATH = path.resolve(ROOT_PATH, '/pxq/dist'); //发布文件所存放的目录

    module.exports = {
    entry: {
    app: APP_FILE
    },
    output: {
    publicPath: '/pxq/dist/', //编译好的文件,在服务器的路径,这是静态资源引用路径
    path: BUILD_PATH, //编译到当前目录
    filename: '[name].js', //编译后的文件名字
    chunkFilename: '[name].[chunkhash:5].min.js',
    },
    module: {
    loaders: [{
    test: /.js$/,//使用正则匹配要处理的文件
    exclude: /^node_modules$/,//排除不处理的目录
    loader: 'babel',//要使用的loader
    include: [APP_PATH]
    }, {
    test: /.css$/,
    exclude: /^node_modules$/,
    loader: ExtractTextPlugin.extract('style', ['css', 'autoprefixer']),
    include: [APP_PATH]
    }, {
    test: /.less$/,
    exclude: /^node_modules$/,
    loader: ExtractTextPlugin.extract('style', ['css', 'autoprefixer', 'less']),
    include: [APP_PATH]
    }, {
    test: /.scss$/,
    exclude: /^node_modules$/,
    loader: ExtractTextPlugin.extract('style', ['css', 'autoprefixer', 'sass']),
    include: [APP_PATH]
    }, {
    test: /.(eot|woff|svg|ttf|woff2|gif|appcache)(?|$)/,
    exclude: /^node_modules$/,
    loader: 'file-loader?name=[name].[ext]',
    include: [APP_PATH]
    }, {
    test: /.(png|jpg)$/,
    exclude: /^node_modules$/,
    loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]',
    //注意后面那个limit的参数,当你图片大小小于这个限制的时候,会自动启用base64编码图片
    include: [APP_PATH]
    }, {
    test: /.jsx$/,
    exclude: /^node_modules$/,
    loaders: ['jsx', 'babel'],
    include: [APP_PATH]
    }]
    },
    plugins: [
    new webpack.DefinePlugin({
    'process.env': {
    NODE_ENV: JSON.stringify('development') //定义编译环境
    }
    }),
    new HtmlWebpackPlugin({  //根据模板插入css/js等生成最终HTML
    filename: '../index.html', //生成的html存放路径,相对于 path
    template: './src/template/index.html', //html模板路径
    hash: false,
    }),
    new ExtractTextPlugin('[name].css')
    ],
    resolve: {
    extensions: ['', '.js', '.jsx', '.less', '.scss', '.css'], //后缀名自动补全
    }
    };
  • 相关阅读:
    Python TIPS上一道关于人民币金额小写转大写的题
    C Primer Plus--C预处理器和C库(1)
    C Primer Plus--位操作
    C Primer Plus--结构和其他数据类型(2)
    计算机缓存方式对于程序运行的影响
    7. 整数反转
    服务器初始化安装docker、docker-compose
    nacos爬坑史-1
    Kafka 报错: Error Uncaught exception in scheduled task 'flush-log'
    CentOS中docker部署的项目CPU占用率持续100%以上
  • 原文地址:https://www.cnblogs.com/fireporsche/p/6289836.html
Copyright © 2020-2023  润新知