gulp,webpack和webpack.DefinePlugin编译时配置不起作用

时间:2017-04-20 02:31:10

标签: javascript webpack gulp

我正在尝试使用webpack与gulp一起在源js文件上执行令牌替换,以便可以为特定的部署环境定制代码。但是,我无法执行所需的转换。我希望将环境替换为生产,但不会发生此类转换。

test.js

 console.log(ENVIRONMENT );

gulpfile.js

var gulp = require('gulp');
var webpack = require("gulp-webpack");

gulp.task('default', ['webpack'], function() { });

gulp.task('webpack', function () {

  return gulp
    .src("test.js")
    .pipe(webpack(require('./webpack.config.js')))
    .pipe(gulp.dest("./results"));
});

webpack.config.js

var path = require("path");
var webpack = require("webpack")

module.exports = {
 output: {
        filename: "out.js"
 },  
  plugins: [
     new webpack.DefinePlugin({
ENVIRONMENT:JSON.stringify("Production")
     }) 
   ]
}; 

这会在results / out.js中创建一个文件,但不会注入生成

0 个答案:

没有答案