0
我有一張使用本地json文件的d3.js。從終端加載本地json數據到d3.js和webpack
爲了使數據可視化,我必須使用網絡服務器,所以我決定使用webpack,因爲它也熱衷於重新加載。
的事情是,我僅限於選定的文件(data.json
),因爲它出現在入口點的文件(index.js
):
index.js
d3.json("data.json", function(error, d) {
// get data and draw chart
當我想顯示我使用的圖表npm start
並轉至localhost:8080
package.json
{
"name": "tutorial",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server",
"build": "babel src -d lib",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-env": "^1.3.3",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"style-loader": "^0.16.1"
}
}
webpack.config.js
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
inject: 'body'
})
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve('dist'),
filename: 'index_bundle.js'
},
module: {
loaders: [
{ test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{ test:/\.css$/,
loader: ['style-loader', 'css-loader'],
exclude: /node_modules/
},
]
},
plugins: [
HtmlWebpackPluginConfig,
new CopyWebpackPlugin([
{ from: 'src/data.json'}
])
]
}
我怎麼能忽略JSON文件作爲參數?例如:
npm start "another_data.json"
或與節點?
node "another_data.json"
我可以用這與故宮?因爲我需要npm for webpack –