Muh*_*hin 3 javascript webpack
我正在使用 Webpack 4 的动态导入。当我构建我的入口文件(app.js)时,在 main.bundle.js 文件中,与其关联的模块无法将它的(模块)位置设置为“dist/{another_module}” '。它设置在根文件夹内。
webpack.config.js
const path = require("path");
module.exports = {
entry: {
main: "./src/app.js"
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].bundle.js",
chunkFilename: "[name].bundle.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
};
Run Code Online (Sandbox Code Playgroud)
源代码/应用程序.js
function getScript() {
return import(/* webpackChunkName: "script" */ "./script").then(res => {
console.log(res.default);
});
}
getScript();
Run Code Online (Sandbox Code Playgroud)
源代码/脚本.js
export default function script() {
console.log("script file is loaded")
}
Run Code Online (Sandbox Code Playgroud)
.babelrc
{
"plugins": ["@babel/plugin-syntax-dynamic-import"]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1913 次 |
| 最近记录: |