laravel项目中npm安装vue小结

693 阅读1分钟

1、千万别用cnpm安装

血的教训,总有莫名其妙的问题

2、安装出错如何清空

rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install

3、注册npm安装源及查看配置项

## 1通过config命令(当前项目)
npm config set registry https://registry.npm.taobao.org
npm info underscore ##(如果上面配置正确这个命令会有字符串response)

## 2命令行指定(当前项目)
npm --registry https://registry.npm.taobao.org info underscore

#全局设置安装源
npm config set registry https://registry.npm.taobao.org --global
#查看配置
npm config ls -l
#验证是否生效
npm config get registry

4、Laravel Mix设置异步导入组件

##step 1
npm install --save babel-plugin-syntax-dynamic-import

创建.babelrc

{
  "plugins": ["syntax-dynamic-import"]
}

配置webpack.mix.js

mix.webpackConfig({
    output: {
        chunkFilename: 'chunks/[name].[chunkhash].js',
        publicPath: '/',
    },
});