vue打包后jquery is not defined和静态资源路径找不到

1、jquery is not defined:

解决:

webpack.prod.conf.js:

new webpack.DefinePlugin({
      'process.env': env,
      $ : 'jquery',
      jQuery : 'jquery'
    }),

改为:

new webpack.ProvidePlugin({
           $: "jquery",
           jQuery: "jquery"
    }),

2、静态资源路径找不到

解决:

config > index.js:

build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    productionSourceMap: true,
    ...
}

改为:

build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',
    productionSourceMap: true,
    ...
}

把绝对路径改为相对路径


你可能感兴趣的:(前端学习)