V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
cinwell
V2EX  ›  分享创造

cooking 1.0 -- 更简单优雅的方式配置 webpack

  •  
  •   cinwell · 2016-09-11 21:55:23 +08:00 · 3449 次点击
    这是一个创建于 2811 天前的主题,其中的信息可能已经有所发展或是发生改变。

    饿了么前端团队开源的基于 webpack 的构建工具 -- cooking ,已经发布了正式版。之前是一个全局安装的命令行工具,能方便的快速创建项目、简化了配置,并且全局安装了开发依赖无需每个项目都安装一份。

    现在升级到 1.0 后将工具拆分 cooking 和 cooking-cli ,前者负责提供简化配置的功能,后者融合了之前的脚手架和依赖管理功能。所以可以按项目需要本地安装依赖还是直接用全局的依赖。

    链接

    简单示范简化后的配置

    var cooking = require('cooking');
    
    cooking.set({
      entry: './src/index.js',
      dist: './dist',
      template: './index.html',
      devServer: { port: 8888, publicPath: '/' },
      postcss: [
        require('postcss-salad')
      ]
    });
    
    module.exports = cooking.resolve();
    

    等同于 webpack 的

    module.exports = {
      entry: './src/index.js',
      output: {
        publicPath: process.env.NODE_ENV === 'production' ? '/dist/' : '/',
        path: require('path').resolve(process.cwd(), './dist'),
        filename: '[name].js'
      },
      module: {
        loaders: [
          {
            test: /\.(jsx?|babel|es6)$/,
            include: process.cwd(),
            exclude: /node_modules|bower_components/,
            loaders: ['babel-loader']
          },
          {
            test: /\.css$/,
            loaders: ['style-loader', 'css-loader', 'postcss-loader']
          }
        ]
      },
      plugins: [
        new HtmlWebpackPlugin({
          filename: 'index.html',
          template: require('path').resolve(process.cwd(), './index.html')
        })
      ],
      postcss: function() {
        return [require('postcss-salad')]
      },
      devServer: { port: 8888 }
    }
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1433 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:25 · PVG 01:25 · LAX 10:25 · JFK 13:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.