webpack

Posted jason-lin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webpack相关的知识,希望对你有一定的参考价值。

json文件

{
  "name": "webpack-study",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1",
    "dev": "webpack-dev-server --open --port 8080 --hot"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-0": "^6.24.1",
    "css-loader": "^0.28.7",
    "file-loader": "^1.1.5",
    "html-webpack-plugin": "^2.30.1",
    "less": "^2.7.3",
    "less-loader": "^4.0.5",
    "node-sass": "^4.5.3",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.19.0",
    "url-loader": "^0.6.2",
    "webpack": "^3.8.1",
    "webpack-dev-server": "^2.9.3"
  },
  "dependencies": {
    "bootstrap": "^3.3.7"
  }
}

配置文件


var path = require(‘path‘);
var htmlWebpackPlugin = require(‘html-webpack-plugin‘);

module.exports = {
  entry: path.join(__dirname, ‘./src/main.js‘),
  output: {
    path: path.join(__dirname, ‘./dist‘),
    filename: ‘bundle.js‘
  },
  plugins: [
    new htmlWebpackPlugin({
      template: path.join(__dirname, ‘./src/index.html‘),
      filename: ‘index.html‘
    })
  ],
  module: {
    rules: [
      { test: /.css$/, use: [‘style-loader‘, ‘css-loader‘] },
      { test: /.less$/, use: [‘style-loader‘, ‘css-loader‘, ‘less-loader‘] },
      { test: /.scss$/, use: [‘style-loader‘, ‘css-loader‘, ‘sass-loader‘] },
      { test: /.(jpg|png|gif|bmp|jpeg)$/, use: ‘url-loader?limit=10394 ‘ },
      { test: /.(ttf|eot|svg|woff|woff2)$/, use: ‘url-loader‘ },
      { test: /.js$/, use: ‘babel-loader‘, exclude: /node_modules/ },
    ]
  }
}

完整demo

https://github.com/Jasonlincoln/webStudy

以上是关于webpack的主要内容,如果未能解决你的问题,请参考以下文章

Vue报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object 的解决方法(代码片段

如何使用webpack加载库源映射?

浅析 -- webpack

报错:✘ http://eslint.org/docs/rules/indent Expected indentation of 0 s paces but found 2(代码片段

报错:✘ http://eslint.org/docs/rules/indent Expected indentation of 0 s paces but found 2(代码片段

无法创建中继容器; graphql.js 文件似乎有 webpack 工件?