首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何配置Webpack在Vue-cli?

如何配置Webpack在Vue-cli?
EN

Stack Overflow用户
提问于 2018-03-04 11:09:37
回答 1查看 16K关注 0票数 9

编辑:我不再试图让这个工作了。

我使用Vue-cli (https://github.com/chrisvfritz/vue-enterprise-boilerplate),它使用Webpack在水下创建一个网站.

现在我想更改我的webpack.config.js,但是这个文件不存在。

vue.config.js包含一个configureWebpack属性,但它的格式似乎与正常的Webpack配置不同。

我想使用的Webpack配置如下:

代码语言:javascript
复制
// Webpack config
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const StartServerPlugin = require('start-server-webpack-plugin');

module.exports = {
    entry: ['webpack/hot/poll?1000', './src/index'],
    watch: true,
    target: 'node',
    node: {
        __filename: true,
        __dirname: true
    },
    externals: [nodeExternals({ whitelist: ['webpack/hot/poll?1000'] })],
    module: {
        rules: [
            ...
        ]
    },
    plugins: [
        new StartServerPlugin('server.js'),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.DefinePlugin({
            'process.env': { BUILD_TARGET: JSON.stringify('server') }
        })
    ],
    output: { path: path.join(__dirname, 'dist'), filename: 'server.js' }
};

我不知道在我的vue.config.js中该放在哪里,看起来是这样的:

代码语言:javascript
复制
// Vue config
const appConfig = require('./src/app.config')

module.exports = {
  configureWebpack: {
    // We provide the app's title in Webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: appConfig.title,
    // Set up all the aliases we use in our app.
    resolve: {
      alias: require('./aliases.config').webpack,
    },
    module: {
      rules: [
        {
          test: /\.styl$/,
          use: [
            'style-loader',
            {
              loader: 'css-loader',
              options: {
                modules: true,
                localIdentName: '[name]__[local]___[hash:base64:5]',
              },
            },
            'stylus-loader',
          ],
        },
      ],
    },
  },
  css: {
    // Enable CSS source maps.
    sourceMap: true,
    // Enable CSS modules for all CSS/pre-processor files.
    // This option does not affect *.vue files.
    modules: true,
  },
  // Split dependencies into their own bundle.
  // https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode
  dll: true,
  // Configure Webpack's dev server.
  // https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md
  devServer: {
    ...(process.env.API_BASE_URL
      ? // Proxy API endpoints to the production base URL.
        { proxy: { '/api': { target: process.env.API_BASE_URL } } }
      : // Proxy API endpoints a local mock API.
        { before: require('./tests/mock-api') }),
  },
}

到目前为止,我已经尝试过webpack.config.jsapp.config.js,但是现在Vue-cli抱怨没有满足依赖关系。

代码语言:javascript
复制
These dependencies were not found:

* @components/_globals in ./src/main.js
* @router in ./src/main.js
...
EN

回答 1

Stack Overflow用户

发布于 2018-08-16 12:01:03

Vue CLI 3.0.0的解决方案

在项目主目录中创建vue.config.js文件:

代码语言:javascript
复制
module.exports = {
  configureWebpack: {
    devServer: {
        watchOptions: {
          ignored: ['node_modules'],
          aggregateTimeout: 300,
          poll: 1500
        },
        public: '192.168.56.132' // vagrant machine address
    }
  }
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49094720

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档