Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
配置npm&;使用相对路径的长路径的网页包Win10_Npm_Webpack_Config_Long Path - Fatal编程技术网

配置npm&;使用相对路径的长路径的网页包Win10

配置npm&;使用相对路径的长路径的网页包Win10,npm,webpack,config,long-path,Npm,Webpack,Config,Long Path,当前网页包捆绑项目文件夹结构(win10): 根文件夹\ |--节点_模块 |--src |--index.js |--template.html |--package.json |--webpack.config.js index.js的内容: console.log(“你好网页”) template.html的内容: <!DOCTYPE html> <html lang="en"> <head>

当前网页包捆绑项目文件夹结构(win10)
根文件夹\
|--节点_模块
|--src
|--index.js
|--template.html
|--package.json
|--webpack.config.js

index.js的内容:
console.log(“你好网页”)

template.html的内容

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title><%= htmlWebpackPlugin.options.title %></title>
    </head>
    <body>
        <div id="root"></div>
    </body>
    </html>

webpack.config.js的内容:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    entry: {
        main: path.resolve(__dirname, './src/index.js'),
    },
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: '[name].bundle.js',
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: 'webpack Boilerplate',
            template: path.resolve(__dirname, './src/template.html'), // template file
            filename: 'index.html', // output file
        }),
    ]
};

如何使此文件夹完全可移植,即在运行
npx webpack
npm run build
时,无论使用
C:\root\u folder\
C:\very\longpath\root\u folder
都可以运行良好。
C:\root\u folder\
中成功运行了这个示例的
npx webpack
,然后我将**root\u folder**复制到
D:\testing\root\u folder\
中,当从
D:\testing\root\u folder\
运行
npx webpack
时,它工作了,这显然表明它是可移植的。
小结:如果网页包绑定项目属于其自己的项目子文件夹中的其他项目,则将其根文件夹存储在它们自己的项目子文件夹中是很有帮助的,因此,有时可以在嵌套文件夹中存储根文件夹是很有帮助的。
问题:是否有一种方法可以在windows中使用简单的npm脚本甚至npx命令解析所有具有本地路径的根文件夹/脚本,从而不会对长路径返回错误?

当前答案:很好的解决方法是将嵌套的root_文件夹复制到一个临时的
C:\temp\root_文件夹
,并从那里执行所有npm网页包处理和模块绑定。因此,在这里工作的答案是装载项目目录并从那里运行构建

所有必要的是拥有以下npm脚本(在package.json中):

“脚本”:{
“测试”:“ECHO\”错误:未指定测试\“&退出1”,
“构建”:(如果存在\%CD%/dist\'RMDIR dist/S/Q)和网页包(&W),
“nestingcompliance:build”:“SUBST Z:\%CD%\”和&PUSHD Z:&npm运行构建和&POPD&&SUBST Z:/D”
}
然后在命令行中运行:

npm run nestingcompliance:build
npm run nestingcompliance:build