をconfig.jsonするコンパイル:のWebPACK <strong>config.jsの</strong>このことから、たとえばコンパイルする方法があるconfig.jsのは
module.exports = {
param: 'value',
param1: 'value2'
}
出力のためのconfig.jsonファイルにJSON形式にこれをコンパイルするには..いくつかのローダー?
をconfig.jsonするコンパイル:のWebPACK <strong>config.jsの</strong>このことから、たとえばコンパイルする方法があるconfig.jsのは
module.exports = {
param: 'value',
param1: 'value2'
}
出力のためのconfig.jsonファイルにJSON形式にこれをコンパイルするには..いくつかのローダー?
これはあなたが探しているものですか?
var myConfig = {
param: 'value',
param1: 'value2'
};
console.log(JSON.stringify(myConfig)); // You can delete this if you want.
fs = require('fs');
fs.writeFile('config.json', JSON.stringify(myConfig), function (err) {
if (err) {
return console.log(err);
}
});
module.exports = myConfig;
解決済み!それはと呼ばれるモジュールでかなり簡単でした。module.rules
に1つのルールを追加するだけでした。 Webpackのサンプル構成:
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: "./app.js"
output: {
filename: "bundle.js"
},
module: {
rules: [{
test: /\.json\.js/,
// extract the text
use: ExtractTextPlugin.extract({
use: {}
})
}]
},
plugins: [
new ExtractTextPlugin('config.json', {
// some options if you want
})
]
}
config.json.jsファイルでエクスポートするときにオブジェクトを文字列にすることを忘れないでください。
module.exports = JSON.stringify({
param: 'value',
param1: 'value2'
});
つまり、誰かを助けることを願っています。
ありがとうございました!あれは。しかし、それはwebpackで動作しません。 config.jsonは作成されません。おそらくwebpackの解決策がありますか? –