【发布时间】:2021-06-21 20:36:55
【问题描述】:
知道为什么这个webpack.config.js 没有设置全局LESS 变量:current-vehicle 定义在:/resources/scripts/theme.js 上吗?
/webpack.config.js
const merge = require("webpack-merge");
const path = require("path");
const baseConfig = require("laravel-mix/setup/webpack.config");
require('dotenv').config();
/**
* Update the output directory and chunk filenames to work as expected.
*
* @param {object} config - The webpack config
*
* @return {object} The updated webpack config
*/
const addOutputConfiguration = config => {
const publicPath = process.env.CDN_URL + '/js/';
return merge(config, {
output: {
path: path.resolve(__dirname, "public/cdn/js"),
publicPath,
chunkFilename: "[name].js"
},
module: {
loaders: [
{
loader: 'less-loader',
options: {
modifyVars: require("./resources/scripts/theme")
}
},
],
},
});
};
module.exports = addOutputConfiguration(baseConfig);
这里有完整的 repo:https://github.com/tlg-265/issue-import-less.local
设置
$ git clone https://github.com/tlg-265/issue-import-less.local
$ cd issue-import-less.local
$ npm i
$ npm run watch
Then open with the browser (you do NOT need a server).
LESS 变量:current-vehicle 在此处读取:
当你这样做时:$ npm run watch,你会得到错误:Variable @current-vehicle is undefined,如下面的截图所示:
理想情况下,当你运行它时,你应该在浏览器上得到以下信息:
当点击链接时,你应该得到:
但很遗憾我还没能到达那里。
知道如何让它发挥作用吗?
提前致谢!
【问题讨论】:
-
试过了吗? link
-
关于如何将其集成到我的存储库中的任何想法?你可以试试吗?
标签: node.js reactjs webpack laravel-mix less-loader