美文网首页
phoenix中使用webpack替换掉brunch

phoenix中使用webpack替换掉brunch

作者: aoners | 来源:发表于2018-11-19 22:55 被阅读0次

    首先删除掉brunch相关配置

    yarn remove babel-brunch brunch clean-css-brunch uglify-js-brunch
    rm brunch-config.js
    

    将Webpack添加到package.json中

    yarn add --dev webpack webpack-cli
    

    将Babel添加到package.json

    yarn add --dev babel-cli babel-core babel-loader babel-preset-es2015
    

    更新package.json scripts

    "scripts": {
      "deploy": "webpack --mode production",
      "start": "yarn run watch",
      "watch": "webpack --mode development --watch-stdin"
    }
    

    创建一个webpack.config.js文件

    const path = require('path');
    module.exports = function(env) {
      const production = process.env.NODE_ENV === 'production';
      return {
        devtool: production ? 'source-maps' : 'eval',
        entry: './js/app.js',
        output: {
          path: path.resolve(__dirname, '../priv/static/js'),
          filename: 'app.js',
          publicPath: '/',
        },
        module: {
          rules: [
            {
              test: /\.js$/,
              exclude: /node_modules/,
              use: {
                loader: 'babel-loader',
              },
            },
          ],
        },
        resolve: {
          modules: ['node_modules', path.resolve(__dirname, 'js')],
          extensions: ['.js'],
        },
      };
    };
    

    更新 config/dev.exs的watchers

    watchers: [yarn: ["run", "watch", cd: Path.expand("../assets", __DIR__)]]
    
    mix phx.server
    

    相关文章

      网友评论

          本文标题:phoenix中使用webpack替换掉brunch

          本文链接:https://www.haomeiwen.com/subject/tfuzfqtx.html