webpack-dev-server 配置

摘要:
==-1;varconfig={//Thestandardentrypointandoutputconfigentry:entry,output:{path:path.join(__dirname,"assets2"),//path.join(__dirname,"assets","[hash]"),//publicPath:"//s3-us-west-1.amazonaws.com/chime-static-cloud/site/assets/",publicPath:"/static/new-template/",filename:"[name].js",chunkFilename:"bundle-[id].js"},/*entry:"./entry.js",output:{path:__dirname,filename:"bundle.js"},*/module:{loaders:[//Extractcssfiles{test:/.css$/,loader:ExtractTextPlugin.extract("style-loader",`css-loader${needCsshint?'!csslint-loader':''}!autoprefixer-loader`)},//Optionallyextractlessfiles//oranyothercompile-to-csslanguage{test:/.less$/,loader:ExtractTextPlugin.extract("style-loader",`css-loader${needCsshint?'!csslint-loader':''}!autoprefixer-loader!less-loader`)},{test:/.(sass|scss)/,loader:ExtractTextPlugin.extract("style-loader",`css-loader${needCsshint?'!csslint-loader':''}!autoprefixer-loader!sass-loader?outputStyle=expanded`)},//Youcouldalsouseotherloadersthesameway.I.e.theautoprefixer-loader{test:/.woff2$/,loader:'url-loader?limit=1000000&name=build/[name].[ext]'},{test:/.(png|jpg|svg|gif)$/i,loaders:['url-loader?name=build/[name].[ext]','image-webpack']},{test:/.tpl.html$/,loader:'html-template-loader'},{test:/.jsx?$/,loader:'babel-loader',exclude:/node_modules|lib/,query:{presets:['es2015','react']}}]},//Usetheplugintospecifytheresultingfilename(andaddneededbehaviortothecompiler)plugins:[newExtractTextPlugin("[name].css"),newCommonsChunkPlugin({name:"search-app.chunk",chunks:isDevServer?[]:["search-app-init","template-home","listing-detail","search-map"]}),newCommonsChunkPlugin({name:"common-app.chunk",//chunks:isDevServer?
webpack.config.js 配置

var ExtractTextPlugin = require("extract-text-webpack-plugin");
var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
var AssetsPlugin = require('assets-webpack-plugin');
var path = require("path");
var umdREquirePlugin = require("umd-require-webpack-plugin");
var MoveToParentMergingPlugin = require('move-to-parent-merging-webpack-plugin');
var hotModuleReplacementPlugin = require("webpack/lib/HotModuleReplacementPlugin");
var webpack = require("webpack");

var isDevServer = process.argv[1].indexOf('webpack-dev-server') !== -1;

var devServer = {
    historyApiFallback: true,
    hot: true,
    inline: true,
    progress: true
};

var entry = require("./entry-2");
var modulesEntry = require("./modules/entry");
for (var key in modulesEntry) {
    entry[key] = modulesEntry[key];
}

var needCsshint = process.argv.indexOf('--csshint') !== -1;
var config = {
    // The standard entry point and output config
    entry: entry,
    output: {
        path: path.join(__dirname, "assets2"), //path.join(__dirname, "assets", "[hash]"),
        //publicPath: "//s3-us-west-1.amazonaws.com/chime-static-cloud/site/assets/",
        publicPath: "/static/new-template/",
        filename: "[name].js",
        chunkFilename: "bundle-[id].js"
    },
    /*
        entry: "./entry.js",
        output: {
            path: __dirname,
            filename: "bundle.js"
        },
    */
    module: {
        loaders: [
            // Extract css files
            {
                test: /.css$/,
                loader: ExtractTextPlugin.extract("style-loader", `css-loader${needCsshint ? '!csslint-loader' : ''}!autoprefixer-loader`)
            },
            // Optionally extract less files
            // or any other compile-to-css language
            {
                test: /.less$/,
                loader: ExtractTextPlugin.extract("style-loader", `css-loader${needCsshint ? '!csslint-loader' : ''}!autoprefixer-loader!less-loader`)
            }, {
                test: /.(sass|scss)/,
                loader: ExtractTextPlugin.extract("style-loader", `css-loader${needCsshint ? '!csslint-loader' : ''}!autoprefixer-loader!sass-loader?outputStyle=expanded`)
            },
            // You could also use other loaders the same way. I. e. the autoprefixer-loader
            {
                test: /.woff2$/,
                loader: 'url-loader?limit=1000000&name=build/[name].[ext]'
            }, {
                test: /.(png|jpg|svg|gif)$/i,
                loaders :[
                   'url-loader?name=build/[name].[ext]',
                   'image-webpack'
                ]
            }, {
                test: /.tpl.html$/,
                loader: 'html-template-loader'
            }, {
                test: /.jsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules|lib/,
                query: {
                    presets: ['es2015', 'react']
                }
            }
        ]
    },

    // Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
    plugins: [
        new ExtractTextPlugin("[name].css"),
        new CommonsChunkPlugin({
            name: "search-app.chunk",
            chunks: isDevServer ? [] : ["search-app-init", "template-home", "listing-detail", "search-map"]
        }),
        new CommonsChunkPlugin({
            name: "common-app.chunk",
            //chunks: isDevServer ? [] : entryArray

            chunks: isDevServer ? [] : ["app-init","listing-detail","sell","blog","sell-report","neigh","nbhd-detail","blog-detail","search-map","profile","template-home","contact","template-evaluation","evaluation-step1","evaluation-step1-new","evaluation-step2","evaluation-step2-new","evaluation-step3","template-about","template-listing-feature","template-listing-sold", "search-app.chunk"]
        }),
        //new CommonsChunkPlugin("search-app.chunk.js", ["search-app", "home", "listing-detail"]),
        new AssetsPlugin({filename: './version-control/source-map-test-2.json', prettyPrint: true}),

        new MoveToParentMergingPlugin(),
        new umdREquirePlugin(),
        new hotModuleReplacementPlugin(),
        //new webpack.optimize.UglifyJsPlugin()
    ],

    resolve: {
        modulesDirectories: ['.', 'node_modules']
    },

    resolveLoader: {
        modulesDirectories: ['.', 'node_modules']
    },
    externals:{
        "jquery":"jQuery",
        "react" : "React",
        "react-dom" :"ReactDOM"
    },

    devServer: isDevServer ? devServer : "",
};

//运行`node js-exclude.js js,new-template/js "js,jsx"`会生成最新的.jsexclude文件
if(process.argv.indexOf('--jshint') !== -1){
    var jshint = JSON.parse(require('fs').readFileSync('./.jshintrc').toString().replace(///[^
]+/g, ''));
    var jsExcludes = require('fs').readFileSync('./.jsexclude').toString().split(/
|
|
/).map(function(item){
        return path.normalize(__dirname + '/' + item);
    });
    config.module.preLoaders = [{
        test: /.js$/,
        exclude: function(file){
            return jsExcludes.indexOf(file) !== -1 || /[/\]node_modules[/\]/.test(file) || !/[/\]site[/\]/.test(file)
        },
        loader: "jshint-loader"
    }];
    config.jshint = jshint;
}
//运行`node js-exclude.js css,sass,jsp/custom-style,new-template/sass "css,scss,less"`会生成最新的.cssexclude文件
if(needCsshint){
    var cssExcludes = require('fs').readFileSync('./.cssexclude').toString().split(/
|
|
/).map(function(item){
        return path.normalize(__dirname + '/' + item);
    });

    config.csslint = {
        rules: {
            // 'box-model': 1,
            'display-property-grouping': 1,
            // 'duplicate-properties': 1,
            'empty-rules': 1,
            'known-properties': 1,
            'ids': 1,
            'multi-rules-newline': 1,
            'rule-name': 1
        },
        exclude: function(file){
            return cssExcludes.indexOf(file) !== -1 || /[/\]node_modules[/\]/.test(file) || !/[/\]site[/\]/.test(file)
        },
    };
}

module.exports = config;
webpack-dev-server 配置
var WebpackDevServer = require("webpack-dev-server");
var webpack = require("webpack");

var compiler = webpack({
  // configuration
});
var server = new WebpackDevServer(compiler, {
  // webpack-dev-server options

  contentBase: "/Users/yincheng/code/homethy-static/site/",
  // or: contentBase: "http://localhost/",

  hot: true,
  // Enable special support for Hot Module Replacement
  // Page is no longer updated, but a "webpackHotUpdate" message is send to the content
  // Use "webpack/hot/dev-server" as additional module in your entry point
  // Note: this does _not_ add the `HotModuleReplacementPlugin` like the CLI option does. 

 / Set this as true if you want to access dev server from arbitrary url.
  // This is handy if you are using a html5 router.
  historyApiFallback: false,

  // Set this if you want to enable gzip compression for assets
  compress: true,

  // Set this if you want webpack-dev-server to delegate a single path to an arbitrary server.
  // Use "*" to proxy all paths to the specified server.
  // This is useful if you want to get rid of 'http://localhost:8080/' in script[src],
  // and has many other use cases (see https://github.com/webpack/webpack-dev-server/pull/127 ).
/*
  proxy: {
    "*": "http://localhost:9090"
  },
*/

  // pass [static options](http://expressjs.com/en/4x/api.html#express.static) to inner express server
  staticOptions: {
  },

  // webpack-dev-middleware options
  quiet: false,
  noInfo: false,
  lazy: true,
  filename: "bundle.js",
  watchOptions: {
    aggregateTimeout: 300,
    poll: 1000
  },
  publicPath: "/site/",
  headers: { "X-Custom-Header": "yes" },
  stats: { colors: true }
});
server.listen(8080, "localhost", function() {});

免责声明:文章转载自《webpack-dev-server 配置》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇自定义mysql函数时报错,[Err] 1418高等代数(二)预习——3、最大公因式下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Linux服务部署Yapi项目(安装Node Mongdb Git Nginx等) Linux服务部署Yapi

一,介绍与需求  1,我的安装环境:CentOS7+Node10.13.0+MongoDB4.0.10。  2,首先安装wget,用于下载node等其他工具 1 yum install -y wget  编译依赖 gcc 环境 1 yum install gcc-c++ 二,Node安装配置 第一步:下载Node 1 wget https://nodejs...

PHP面试题详解

自己从网上找了几份常考到的PHP面试题进行了整理,然后才有了这份PHP面试题,并且我把所有的题目进行了详细分析和代码分析,希望可以对大家有帮助,谢谢大家。 这份试题我也上传到了百度云,有需要的可以直接去百度云下载这份试题,希望可以帮到大家。 链接:http://pan.baidu.com/s/1i5oTN7n 密码:ykws PHP面试题 一、选择题 1....

在webView 中使用JS 调用 Android / IOS的函数 Function

最近做一个项目,混合了NativeCode 和 HTML,为了便于JS 调用App的一些方法,统一封装一个Js方法,记录如下 Android 端首先要再WebView中允许JS的调用 WebView myWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = myW...

属性框架Fixjs——显示基类DisplayObject

首先声明,我是一个菜鸟。一下文章中出现技术误导情况盖不负责 Fixjs分析Fixjs是我打算在javascript技术范畴开始积聚的一个框架项目,这套框架主要为开发庞杂组件供给底层的框架支持。 框架的类与接口我会尽量参考flash框架的实现。同时,我也会开放Fixjs的源代码,欢送同仁一起学习、交流。 DisplayObject在flash中,Displ...

移动端及vue相关问题

1-pc端与移动端  PC下,html在默认情况下以可视区域宽度为基准。移动设备没有适配时,html宽度为980. 2-1像素还原 获取像素比: window.devicePixelRatio 计算缩放比:1 / window.devicePixelRatio 3-单位 px:固定值,绝对单位;%:相对单位;em:相对单位,相对于自身或者父级元素字体大小计...

多页应用 Webpack4 配置优化与踩坑记录

前言 最近新起了一个多页项目,之前都未使用 webpack4 ,于是准备上手实践一下。这篇文章主要就是一些配置介绍,对于正准备使用 webpack4 的同学,可以做一些参考。 webpack4 相比之前的 2 与 3,改变很大。最主要的一点是很多配置已经内置,使得 webpack 能“开箱即用”。当然这个开箱即用不可能满足所有情况,但是很多以往的配置,其实...