我意识到这个问题有点不存在,而且信息量不大,但webpack代码在基于Linux的系统上运行完美。
简单地说,脚本采用env
变量,这是一个文件夹名称(包含要编译的js),然后编译给定文件夹中的每个js文件。从中创建一些js,然后在compile.js
完成业务后将其传递给webpack
。
的package.json
"start_windows": "set BABEL_ENV=development/client&&npm run clean && webpack --watch",
我很惊讶webpack的第14行没有运行console.info("sdhfjkzhsdkfhzsdjkfh================",env);
webpack.base.config.js
const path = require("path");
const getEntries = require("./scripts/build/getEntries");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const WebpackShellPlugin = require("webpack-shell-plugin");
const envGenerator = require("./scripts/build/handleEnv");
const LiveReloadPlugin = require("webpack-livereload-plugin");
console.info("aaaaaaaaaaaaaaaaaaaaaaa");
/**
* Webpack config
*/
module.exports = function() {
const optionsReload = {};
const env = envGenerator(process.env.npm_config_argv);
console.info("sdhfjkzhsdkfhzsdjkfh================",env);
return {
entry: getEntries(env),
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true
}),
new ExtractTextPlugin("[name]/styles.css"),
new LiveReloadPlugin(optionsReload),
new WebpackShellPlugin({
onBuildEnd: ["node ./scripts/build/compile.js"],
dev: false // Allows script to run more than once (i.e on every watch)
})
],
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ["css-loader", "postcss-loader", "sass-loader"]
})
}
]
},
output: {
path: path.join(__dirname, "dist"),
publicPath: "/dist/",
filename: "[name]/script.js"
}
};
};
cygwin的
shruti@ASGLH-WL-12111 /cygdrive/c/Source/asos-mvt-framework
$ npm run build -- -env T1106-premier-upsell
> mvt-framework@0.0.2 build C:\Source\asos-mvt-framework
> npm run clean && webpack -p "-env" "T1106-premier-upsell"
npm WARN invalid config loglevel="notice"
> mvt-framework@0.0.2 clean C:\Source\asos-mvt-framework
> rm -rf ./dist/*
3.8.1 //output here where webpack should be running
> mvt-framework@0.0.2 postbuild C:\Source\asos-mvt-framework
> node ./scripts/build/compile.js
C:\Source\asos-mvt-framework\dist []
getEntries.js
const fs = require("fs");
const path = require("path");
// Directory where our Multi Variant Tests reside
const mvtFolderPath = path.resolve("./src/tests");
/**
* Loop through the JS files in the test folder root
* and define a new bundle for each one
*/
module.exports = function(testFolderName) {console.info(testFolderName);
const entries = {};
const testFolderPath = path.resolve(mvtFolderPath, testFolderName);
fs.readdirSync(testFolderPath).forEach(file => {
const fileName = path.parse(file).name;
const fileExt = path.parse(file).ext;
if (fileExt === ".js") {
entries[fileName] = path.resolve(testFolderPath, file);
}
});
return entries;
};
handleEnv.js
module.exports = function(env) {
console.info(env);
const envCooked = JSON.parse(env).cooked;
if (envCooked.length === 1) {
// eslint-disable-next-line no-console
console.error("\x1b[31m%s\x1b[0m", "ERROR: Please supply a test folder");
console.error(
"\x1b[31m%s\x1b[0m",
"For Example: `npm start T9999-somme-test`"
);
console.info(`
No env given
`);
process.exit();
}
return envCooked[3].substr(0, 1) === "T" ? envCooked[3] : envCooked[4];
};