0
我一直在爲reactjs項目工作一段時間。我決定在項目中使用第三方庫。Reactjs webpack配置問題
我安裝了庫並導入它,我可以從node_modules訪問這個庫。
但我怕這個庫無法訪問它自己的CSS和SCSS文件,所以我決定webpack配置是在這背後。所以我在這裏發佈我的webpack conidration文件。
var path = require("path");
var DIST_DIR = path.resolve(__dirname, "dist");
var SRC_DIR = path.resolve(__dirname, "src");
var config = {
entry: SRC_DIR + "/app/index.js",
output: {
path: DIST_DIR + "/app",
filename: "bundle.js",
publicPath: "/app/"
},
module: {
loaders: [
{
test: /\.js?/,
include: [SRC_DIR],
loader: "babel-loader",
query: {
presets: ["react", "es2015", "stage-2"]
}
},
{
test: /\.s?css$/,
include: [SRC_DIR],
/* as far as I know directories in here will be searched-
for scss and css files and these files will be loaded.
I'm not sure if I need to import node modules or add it's path here.
Also using sass it throws "unexpected format" from my css files in src path.*/
loaders: ['style', 'css' , 'sass']
}
]
}
};
module.exports = config;
需要注意的是:node_modules不是src目錄
- 如何能第三方模塊訪問他們的CSS和SCSS文件? - 我需要更改此配置嗎?