search

Home  >  Q&A  >  body text

javascript - webpack输出多个目录的问题

用webpack打包的时候 入口文件可以定义多个,输出的时候 用output.path输出文件目录 [name]分别输出文件名,
都打包在了一个目录里 我想输出的时候 输出在不同的目录里 用webpack如何去做呢 ?

PHP中文网PHP中文网2817 days ago253

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-10 16:44:15

     这样配:
      entry: {
        " dir1/dir2/dir3":'./index.jsx'
      }

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-10 16:44:15

    var webpack = require("webpack");
    
    module.exports = {
      entry: {
        file1: "./file1.js",
        file2: "./file2.js"
      },
      output: {
        filename: "file1.bundle.js"
      },
      plugins: [
        new webpack.optimize.CommonsChunkPlugin("file2", "./anotherpath/file2.bundle.js")
      ]
    };

    reply
    0
  • ringa_lee

    ringa_lee2017-04-10 16:44:15

    var getEntry = function(){

    var entry = {};
    glob.sync(__dirname+'/dev/**/*.js').forEach(function(name){
        var n = name.slice(name.lastIndexOf('dev/')+4,name.length-3);
        entry[n] = name;
    });
    return entry;

    }

    module.exports = {

    entry:getEntry(),
    output:{
        path:__dirname+'/public/',
        filename:'[name].js'
    },
    module: {
        loaders: [
              //{ test: /\.less$/, loader: 'style!css!less' }, // use ! to chain loaders
              { test: /\.less$/, loader: ExtractTextPlugin.extract("style-loader!css-loader","less-loader") },
              { test: /\.(png|jpg)$/, loader: 'url?limit=8192'} 
        ]
      },
      resolve: {
          root:__dirname,
        extensions: ['', '.js', '.less']
      },    
    plugins: [commonsPlugin,new ExtractTextPlugin("[name].less",{allChunks:true})]

    }

    reply
    0
  • Cancelreply