简体   繁体   English

Webpack + eslint替换linting上的源代码更改

[英]Webpack + eslint replace source change on linting

Running on webpack dev server with a string replacement plugin that does a replacement based on a function . 在带有字符串替换插件的webpack开发服务器上运行,该插件基于函数进行替换。 I am finding the value of the replacement overwritten my source file . 我发现替换的值覆盖了我的源文件。

My Dev server configuration is this: 我的开发服务器配置是这样的:

const devServer = (options) => {
  return {
    devServer: {
      hot: true,
      inline: true,
      stats: 'errors-only',
      host: options.host,
      port: options.port,
      historyApiFallback: true
    },
    plugins: [
      new webpack.HotModuleReplacementPlugin({
        multiStep: true
      })
    ]
  }
}

The string replacement plugin configuration is: 字符串替换插件的配置为:

  const constants = (data) => {
    return {
      module: {
        loaders: [
          {
            test: /\.jsx?$/,
            loader: StringReplacePlugin.replace({
              replacements:[
                {
                  pattern:/\`CONSTANT_(.*)\`/g,
                  replacement:(match,p1,offset,string)=>{
                    console.log('MATCH '+p1)
                    const keys = p1.split('.')
                    let current = data
                    keys.forEach((key)=>{
                      current = current[key]
                    })
                    console.log('Replacing '+p1+' with '+current)
                    return `'${current}'`
                  }
                }
              ]
            })
          }
        ]
      },
      plugins: [
        new StringReplacePlugin()
      ]
    }
  }

The entry/ouptut values are: 输入/输出值是:

const base = {
  entry: {
    app: path.resolve(PATHS.app, './index.jsx')
  },
  output: {
    path: PATHS.build,
    filename: 'app.js',
    publicPath: '/'
  },
  resolve: {
    extensions: ['', '.js', '.jsx', '.json']
  }
}

Is there any reason why webpack dev server would be changing files on source? Webpack开发服务器会在源上更改文件吗?

EDIT: 1 Added JS part: 编辑:1添加了JS部分:

const js = (paths) => {
  const cacheDir = (process.env.CACHE_DIRECTORY ? process.env.CACHE_DIRECTORY : 'true')
  return {

    module: {
      loaders: [
        {
          test: /\.jsx?$/,
          exclude: /(node_modules|bower_components)/,
          loaders: [
            `babel?cacheDirectory=${cacheDir}`, // presets on .babelrc
            'eslint-loader?fix'
          ],
          include: paths
        }
      ]
    }
  }
}

Edit 2 The cause seesm to be the eslint-loader?fix, when removed the appropriate behaviour is achieved. 编辑2原因似乎是eslint-loader?修复,将其删除后即可实现适当的行为。 Now I am seeking how to prevent that 现在我正在寻找如何防止这种情况

在每次更改之前放置eslint-loader?fix可以防止这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM